Using mvn
and the maven-assembly-plugin
, I create a .jar with dependencies and run it like this:
java -cp ../target/module-jar-with-dependencies.jar module.Launcher --project=example --network=toy_ags_network.sif
I wanted to create a mvn profile that does exactly that. So in my pom.xml
I added this:
<profiles>
<profile>
<id>runExample</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>module.Launcher</mainClass>
<arguments>
<argument>--project</argument>
<argument>example</argument>
<argument>--network</argument>
<argument>toy_ags_network.sif</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<mainClass>com.test.Startup</mainClass>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
So, when I do: mvn compile -P runExample
I would get the same results. It seems though that some classes from a dependency are not fully loaded or something and this throws exceptions, etc. and when I don't include that particular code that uses these other classes then everything is fine. I want to make sure that with my way above I have included all dependencies, e.g. that the java command and the maven one are equal.
I managed to have a simple plugin that behaves the same way as the java command, by running mvn exec:exec
:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<argument>target/module-jar-with-dependencies.jar</argument>
<argument>module.Launcher</argument>
<argument>--project</argument>
<argument>example</argument>
<argument>--network</argument>
<argument>toy_ags_network.sif</argument>
</arguments>
</configuration>
</plugin>
But I want a profile with that plugin inside, that's what I still not have!
The correct configuration for the pom.xml
is:
<profiles>
<profile>
<id>runExample</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<argument>target/module-jar-with-dependencies.jar</argument>
<argument>module.Launcher</argument>
<argument>--project</argument>
<argument>example</argument>
<argument>--network</argument>
<argument>toy_ags_network.sif</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Thus, running: mvn compile -P runExample
is the same as:
java -cp ../target/module-jar-with-dependencies.jar module.Launcher --project=example --network=toy_ags_network.sif