Running perl from maven

Next post in English (probably all short technical post will be in English from now longer and not technical will be still in Polish).

Ad rem. Sometimes one of this strange guys who write in perl/ruby/phyton create some super-fucking-extra script that solve all problems in project but you must run it always when you compile project. Of course you must do it in the right time (after compile and before package) and right way.
Today I need to run perl script that compress css file (remove comments, additional spaces, tabs and extra lines, I white GWT project so short css is a nice feature) and I need run it after compile and before package. I use maven to compile project.
The simplest way is make this process in tree steps. First step is call compile. Second is run script, and third is run package. When We got CI server like Hudson we can create job and forget about it. But when we developing application make two additional steps is not the best idea.
Solution for this problem is use exec-maven-plugin. Listing 1 show simple pom.xml that call Linux tree program with application root directory as argument:

Listing 1. Call tree ./ in the compile phase.


The result of execution:

Listing 2. Result of mvn clean compile.

koziolek@koziolek-desktop:~/workspace/ExecTest$ mvn clean compile
Warning: JAVA_HOME environment variable is not set.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building ExecTest
[INFO]    task-segment: [clean, compile]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /home/koziolek/workspace/ExecTest/target
[INFO] [resources:resources]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/koziolek/workspace/ExecTest/src/main/resources
[INFO] [compiler:compile]
[INFO] Compiling 1 source file to /home/koziolek/workspace/ExecTest/target/classes
[INFO] [exec:exec {execution: exec-tree}]
[INFO] ./
[INFO] |-- pom.xml
[INFO] |-- src
[INFO] |   |-- main
[INFO] |   |   `-- java
[INFO] |   |       `-- pl
[INFO] |   |           `-- koziolekweb
[INFO] |   |               `-- exec
[INFO] |   |                   `-- test
[INFO] |   |                       `--
[INFO] |   `-- test
[INFO] |       `-- java
[INFO] |           `-- pl
[INFO] |               `-- koziolekweb
[INFO] |                   `-- exec
[INFO] |                       `-- test
[INFO] |                           `--
[INFO] `-- target
[INFO]     `-- classes
[INFO]         `-- pl
[INFO]             `-- koziolekweb
[INFO]                 `-- exec
[INFO]                     `-- test
[INFO]                         `-- App.class
[INFO] 19 directories, 4 files
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Tue Jul 07 23:21:17 CEST 2009
[INFO] Final Memory: 11M/118M
[INFO] ------------------------------------------------------------------------

That’s all folks 😉

3 myśli na temat “Running perl from maven

  1. Czytalo sie Ciebie naprawde dobrze, m. in. dlatego, ze nie pisales na sile po angielsku. Skad ta zmiana?

  2. Ponieważ są wakacje i ostatnio wyjechał z kraju ostatni gość z którym mogłem pogadać po angielsku, a z językiem kontakt muszę mieć… Zresztą już wcześniej wrzucałem krótkie teksty techniczne po angielsku. No ale.. skoro taka wola ludu.. to się zobaczy. Zresztą blog przejdzie małą reorganizację mam nadzieję, że po wakacjach będzie zupełnie inaczej.

Napisz odpowiedź

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see