I want to run multiple CMD commands in maven using single pom.xml.
May I know how can I do that?
for example
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>id1</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd1</executable>
</configuration>
</execution>
<execution>
<id>id2</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd2</executable>
</configuration>
</execution>
</executions> </plugin>
You could introduce two different profiles for cmd1 and cmd2.
Maybe exec-maven-plugin:
run a script that will run your cmds sequentially::
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>run a backup</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>/path/to/backup-script/bkp.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
Related
Small question regarding how to start jmxPort randomly, using the spring-boot-maven-plugin please.
Currently, I am running integration test with the spring-boot-maven-plugin, and it needs the jmxPort.
Hence, I am initializing it this way:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<wait>1000</wait>
<maxAttempts>180</maxAttempts>
<jmxPort>0</jmxPort>
<environmentVariables>
<SPRING_PROFILES_ACTIVE>integration</SPRING_PROFILES_ACTIVE>
</environmentVariables>
<jvmArguments>
-Dspring.application.admin.enabled=true
</jvmArguments>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
However, the port 0 is not working.
How to start it randomly please?
Thank you
You can use for example org.codehaus.mojo.build-helper-maven-plugin
https://www.mojohaus.org/build-helper-maven-plugin/
You will add one more step to your plugin config. This step will generate variable with random port number which can be then used with the spring-boot-maven-plugin.
Your configuration will look similar to this:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>random.jmx.port</portName>
</portNames>
<randomPort>true</randomPort>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<wait>1000</wait>
<maxAttempts>180</maxAttempts>
<jmxPort>${random.jmx.port}</jmxPort>
<environmentVariables>
<SPRING_PROFILES_ACTIVE>integration</SPRING_PROFILES_ACTIVE>
</environmentVariables>
<jvmArguments>
-Dspring.application.admin.enabled=true
</jvmArguments>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
I have added 2 plugins under build tag, functionality of both the plugin's is to generate some classes under target folder. Whenever I am trying to clean install maven application, by default target gets clean each time and then installs a fresh content into target folder which is the ideal way.
But in the following code Java classes are generated only when, if there is only single plugin. I have to manually comment any one of the plugin and then I need to install maven goal and then Java classes get generated for a single plugin, same thing I need to repeat for second plugin.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/somefolder</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>somefolder</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>myfirstwsdl.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
<extension>true</extension>
<target>2.2</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>wsimport</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>mysecondwsdl.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
<extension>true</extension>
<target>2.2</target>
</configuration>
</plugin>
</plugins>
</build>
My question is, how can I generate Java classes simultaneously without commenting any one of the plugin under target folder?
You're specifying the same plugin twice, that's not going to work. You need to merge the two like this (move <configuration> inside <execution>):
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>somefolder</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>myfirstwsdl.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
<extension>true</extension>
<target>2.2</target>
</configuration>
</execution>
<execution>
<id>wsimport</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>mysecondwsdl.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
<extension>true</extension>
<target>2.2</target>
</configuration>
</execution>
</executions>
</plugin>
I have the following pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>wizard</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>br.com.rafa.WizardLauncher</mainClass>
</configuration>
</execution>
<execution>
<id>default-cli</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>br.com.rafa.DesktopLauncher</mainClass>
</configuration>
</execution>
</executions>
</plugin>
If I run mvn exec:java, DesktopLauncher is executed.
How can I alternate between the executions from the command line? In other words, I would like to execute WizardLauncher without changing pom.xml.
I need to execute several java classes during maven build phase, but plugin executes only class from first execution
Pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>first</id>
<goals>
<goal>java</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<mainClass>com.myPackage.AssignTest</mainClass>
</configuration>
</execution>
<execution>
<id>second</id>
<goals>
<goal>java</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<mainClass>com.myPackage.CompareTest</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Does somebody know where is an error?
In case someone will want an answer to this.
From experimenting I've found that the java goal does not support multiple executions, but the exec goal does. So just transform java into exec
Below is an example of how to run the above code with the exec goal.
<executions>
<execution>
<id>execution-one</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath/>
<argument>com.myPackage.AssignTest</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>execution-two</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath/>
<argument>com.myPackage.CompareTest</argument>
</arguments>
</configuration>
</execution>
</executions>
If classes you want to run reside in your actual code, you will probably need to bind the exec goal to a phase after compile. Else they will simply be picked up from the project dependencies.
I am learning Maven and have encountered a problem. When I try to do mvn clean install with my webapp i get the error saying that parameters stopPort and stopKey are missing or invalid. Here is what pom.xml looks like:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.17</version>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<stopPort>9999</stopPort>
<stopKey>foo</stopKey>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Any idea what could cause that? Thx in advance.
The problem is that you have only defined the stopPort and stopKey configuration in the run goal. This configuration needs to be moved to be outside the execution section.
So your pom would now be:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.17</version>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<stopPort>9999</stopPort>
<stopKey>foo</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>