How can i pass command line option to phantomjs maven plugin - java

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 :)

Related

Passing multiple arguments to maven

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.

maven exec plugin - <commandlineArgs> doesn't work as expected

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

How do I run the maven exec plugin multiple times in a build

Below is the relevant part of my POM -
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>StartHub</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${basedir}/src/lib/Hub/selenium-server-standalone-2.53.0.jar</argument>
<argument>-role</argument>
<argument>hub</argument>
<argument>-throwOnCapabilityNotPresent</argument>
<argument>false</argument>
<argument>-newSessionWaitTimeout</argument>
<argument>20000</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>StartNode</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${basedir}/src/lib/Node/selenium-server-standalone-2.53.0.jar</argument>
<argument>-hub</argument>
<argument>http://127.0.0.1:4444/register/grid</argument>
<argument>-port</argument>
<argument>5555</argument>
<argument>
Dwebdriver.chrome.driver=${basedir}/chromedriver.exe</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
I was trying to use the exec plugin to execute a jar(selenium standalone server) in two configurations(hub and Node).
My issue is that the jar is executed only once in the configuration specified between the first pair of "execution" tags. I have searched extensively for a solution and the only thing I found was that the id's for different executions need to be different, which I rectified. I still can't seem to manage to run the jars twice even though I can run any one of them successfully if I comment out the execution of the other.
I should also mention that I'm running the project in Eclipse, so ideally what I would want to do is right-click on the POM.xml click on Run-as and select "Maven test".
This is not a Maven executions issue but rather an issue related to what you are executing: a blocking process (the first server) which would stop the build listening for a node which would never get connected (because its execution won't start).
Changing your pom to the following:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>StartHub</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-version</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>StartNode</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-version</argument>
</arguments>
</configuration>
<a/execution>
</executions>
</plugin>
It would perfectly execute the two exec executions, printing twice the Java version. Note: the snippet is a copy and paste from your question, just replacing arguments of the java command to its version option.
What you are most probably looking for is to execute the two commands in background or at least in a non-blocking way in order to get the second executed, then proceed with the build (to execute some tests I presume).
Check this SO question on how to achieve it: instead of using the exec-maven-plugin, use the maven-antrun-plugin to launch the two selenium commands.
As a further note, you should probably consider using the maven-failsafe-plugin instead and execute integration tests, attaching the executions above to the pre-integration-test phase and stop them during the post-integration-test phase in order to properly clean them.

How can i windows command prompt commands from maven pom.xml file?

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.

Maven exec-plugin pom.xml definition: activate shell interpretation for characters

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.

Categories