[英]Problem translating java command to maven profile
Using mvn
and the maven-assembly-plugin
, I create a .jar with dependencies and run it like this: 使用
mvn
和maven-assembly-plugin
,我创建一个带有依赖项的.jar并像这样运行它:
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. 我想创建一个完全相同的mvn配置文件。 So in my
pom.xml
I added this: 所以在我的
pom.xml
我添加了这个:
<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. 所以,当我这样做:
mvn compile -P runExample
我会得到相同的结果。 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, eg that the java command and the maven one are equal .
我想确保以上面的方式我已经包含了所有依赖项,例如java命令和maven一样 。
I managed to have a simple plugin that behaves the same way as the java command, by running mvn exec:exec
: 我设法有一个简单的插件,其行为与java命令相同,通过运行
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: pom.xml
的正确配置是:
<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: 因此,运行:
mvn compile -P runExample
与:
java -cp ../target/module-jar-with-dependencies.jar module.Launcher --project=example --network=toy_ags_network.sif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.