0

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.

Edits

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!

John
  • 359
  • 4
  • 19
  • I've just check and it works for me. If I add some dependency (e.g `junit` with a compile scope instead of test) and run it as You did using maven, I get (last lines): [INFO] --- exec-maven-plugin:1.6.0:java (default) @ ploter --- some class from dependency (Test.class.toString()): interface org.junit.Test Parameters: --project example --network toy_ags_network.sif [INFO] - [INFO] BUILD SUCCESS [INFO] - INFO] Total time: 1.887 s [INFO] Finished at: 2019-05-09T14:02:43+02:00 – zolv May 09 '19 at 12:03
  • @zolv it works for me also for other dependencies but not for a particular one. Something has to be different in the way of executing these two commands (through mvn and java) **or** something strange happens in that dependency... – John May 09 '19 at 12:19
  • Can You plese check what is the `scope` of dependencies You miss? Is it `runtime`? – zolv May 09 '19 at 12:34
  • No, it's compile scope (default). I managed to run a plugin, I will include it in the question. – John May 09 '19 at 12:44

1 Answers1

0

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
John
  • 359
  • 4
  • 19