I use the Maven plugin exec and have defined it in a profile of my pom.xml like this:
<profile>
<id>optimizepng</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>optipng</executable>
<arguments>
<argument>src/main/webapp/images/*.png</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Now, if I set the argument that I defined in this code sample to <argument>-h</argument>, the terminal call mvn org.codehaus.mojo:exec-maven-plugin:exec -P optimizepng works as expected and prints out the help of optipng.
What I figured out is, that the asterisk may not be interpreted as a shell character. Could this be the reason for it? If so, is there a tag that I can apply anywhere to toggle shell interpretation?
Additional info on my plan in the first place:
I want to optimize all png files in the src/main/webapp/images/ folder, using optipng. What I would use as a shell command is optipng src/main/webapp/images/*.png.
Okay, now that was quick. I figured out, I could just start the shell instead and let it interpret the terminal call I want to execute.
<configuration>
<executable>sh</executable>
<arguments>
<argument>-c</argument>
<argument>optipng src/main/webapp/images/*.png</argument>
</arguments>
</configuration>
This code sample is what I had to fix, so this does the job.
Related
I wrote a simple cli program to get input from the CLI when invoking. I was able to do this by adding the exec plugin in the pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.mavericks.App</mainClass>
<arguments>
<argument>names.txt</argument>
<argument>expense.txt</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
But when I try to invoke the same thing via cli
mvn exec:java -Dexec.mainClass=“com.mavericks.App” -Dexec.args=“'names.txt' 'expense.txt'”
Unknown lifecycle phase "expense.txt”". You must specify a valid lifecycle phase or a goal. Help would be much appreciated.
As per slinlok's comment it worked with these above modification,
mvn exec:java -Dexec.mainClass=com.mavericks.App -Dexec.args="names.txt expense.txt"
thanks.
Im using phantomjs-maven-plugin in my Java project.
I was trying to pass command line option to phantomjs with my pom.xml
something like that(described in the plugin docs:
<plugin>
<groupId>com.github.klieber</groupId>
<artifactId>phantomjs-maven-plugin</artifactId>
<version>0.7</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>install</goal>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<version>2.1.1</version>
<checkSystemPath>true</checkSystemPath>
<commandLineOptions>--ssl-protocol=any --ignore-ssl-errors</commandLineOptions>
<script>assets/test.js</script>
<arguments>
<argument>${liberty.https.server.port}</argument>
</arguments>
</configuration>
</plugin>
Generally , what i was trying to do is something like that:
phantomjs --ssl-protocol=any --ignore-ssl-errors test.js
but with no luck for now, after hours of searching.
When i sty to run my maven task I get the following error:
[INFO] Executing phantomjs command
Invalid values for 'ssl-protocol' option.
I guess I have some syntax issues with this command line option.
Thanks for your help!
Finally I found what I did wrong here with the configuration.
Just needed to move the <commandLineOptions> to configuration section inside the <execution> area.
it finally will look line that:
<execution>
<phase>integration-test</phase>
<goals>
<goal>install</goal>
<goal>exec</goal>
</goals>
<configuration>
<commandLineOptions>--ssl-protocol=any --ignore-ssl-errors=true</commandLineOptions>
</configuration>
</execution>
and I removed that from the main configuration section below that.
I manage to figure out that what I did before that was to pass command line arguments to the execution of my test.js script and to the execution of the phantom.js .
I hope it will serve some lost guys like me :)
I use maven exec plugin and want to execute simple .exe file with an argument passed in, so the final command line execution would look like:
ISCC.exe setup.iss
I tried to use
<arguments>
<argument>arg1</argument>
...
</arguments>
however it produced output that was not suitable for me:
ISCC.exe, arg1, arg2, arg3
because I didnt want to have commas and wanted to have just spaces instead so decided to use <commandlineArgs>
and finally my build tag is as follows:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
<configuration>
<executable>ISCC.exe</executable>
<commandlineArgs>
setup.iss
</commandlineArgs>
</configuration>
</plugin>
</plugins>
</build>
but when I run maven, it produces the command line execution just as it was previously:
ISCC.exe, setup.iss
i.e. with comma instead of space
Could you please give a hint of how to fix this,
Cheers
I am making a maven project which is trying to run command prompt commands. I tried Exec Maven Plugin but couldn't do it. I think i'm at wrong way for this. Here is my work for making a file with "Exec Maven Plugin". Can someone make an explanation why this is not working or make a suggestion about new plugin or solution which is working at pom.xml (not Ant).
`<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>mkdir</executable>
<arguments>
<argument>C:\Users\USERNAME\Desktop\FILENAME</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>`
Thank You..
This is just a workaround you can try until someone comes up with a better answer. (I will remove it afterwards probably)
Instead of executing commands directly, you can create a bash/batch script and try to execute that. For example:
<execution>
<id>Some ID</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/do_stuff.sh</executable>
</configuration>
</execution>
It's basically the same thing, but you can use the normal syntax in the script, instead of the XML syntax in the POM file.
The idea is to run "mvn package", as usual, and after all the steps are done, a Jar utility should be called passing the filepath of the packaged code (a jar or a war file) as an argument.
The utility would be called as follows from the command line:
java -jar Utility.jar -filepath {path of the new jar/war file}
I want to integrate that final step to the build process. How do I modify the pom.xml file in order to accomplish this?
have a look at the maven exec plugin. you can bind an execution of it to the package phase (would run after the built-in bindings defined by the packaging) to run java (the executable) with the arguments "-jar Utility.jar -filepath ${project.build.directory}/${project.artifactId}-${project.version}-${project.packaging}"
the result would look kinda like this:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>run jar utility</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>Utility.jar</argument>
<argument>-filepath</argument>
<argument>${project.build.directory}/${project.build.finalName}.${project.packaging}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
though this invocation would be platform specific. you could improve on this a bit and use "java" instead of "exec" (you'd need to provide the main class name in that Utility.jar)
if you describe what the utility you plan on using does there might be a more cross-platform way to do it (for example the maven antrun plugin)
Here's an alternative way to run the exec-maven-plugin from what #radai suggested. If you can do it this way instead, I recommend it.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<inherited>false</inherited>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<!--I don't want my project's dependencies in the classpath-->
<includeProjectDependencies>false</includeProjectDependencies>
<!--Just include the dependencies that this plugin needs. IE: the Utility dependencies-->
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>com.utility</groupId>
<artifactId>Utility</artifactId>
</executableDependency>
<mainClass>com.utility.MyMainClass</mainClass>
<!--You may be able to use a variable substitution for pathToJarFile. Try it and see-->
<commandlineArgs>-filepath pathToJarFile</commandlineArgs>
</configuration>
<dependencies>
<dependency>
<groupId>com.utility</groupId>
<artifactId>Utility</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>