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
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 am quite new with using maven options - so sorry for an easy question.
I have asked beforehand about how to run java code (call function) and get a clear answer.. but
it seems something is wrong in this config. Or is it because I am not using a correct parameters for startup?
<build>
<plugins>
....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.package.Separator.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
I am running my POM with $: mvn exec:exec
And I get such error:
One or more required plugin parameters are invalid/missing for 'exec:exec'
[0] Inside the definition for plugin 'exec-maven-plugin' specify the following:
<configuration>
...
<executable>VALUE</executable>
</configuration>
-OR-
on the command line, specify: '-Dexec.executable=VALUE'
I have read something about this error and tried originally to move the configuration to executions
secondly - specify classpath but nothing happened((
My Main function in Separator.java class is like this:
static public void main(String[] arg) throws ParserConfigurationException, TransformerException, SAXException, IOException {
//and here I call for example
System.out.println("LOL");
}
Some people use: package before goals (for previous versions) but it does not solve my issue.
I have rewrite my POM:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.package.Separator</mainClass>
</configuration>
</plugin>
But now Class not found exception at org.package.Separator
I am using mvn package for compile
I am running my POM with $: mvn exec:exec And I get such error:
Actually you should run
$: mvn exec:java
See example described on exec-maven-plugin:java usage.
Finnaly your plugin description should be as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<id>default-cli</id>
<!--<phase>validate</phase>--> <!-- or any other phase you want. -->
<phase>integration-test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.package.Separator</mainClass>
</configuration>
</plugin>
Note! This plugin will work only on full name declaration in console or via phase execution:
$: mvn org.codehaus.mojo:exec-maven-plugin:1.3.2:java
$: mvn integration-test
First try renaming the classpath of your project org.package.Separator.Main
"package" is used in java namespace syntax, so don't use it in your packages classpath.
And maybe you should try adding phase to your goal like this :
...
<executions>
<execution>
<phase>run</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.package.Separator.Main</mainClass>
</configuration>
</execution>
</executions>
...
and execute : mvn compile run
I had the same problem. My problem was my code was NOT in src/main/java. your class containing main method must be under src/main/java
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.
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.