Maven:如何在分叉JVM中执行依赖项?
我的存储库中有一个jar程序,用于验证项目中的一些文件。当验证失败时,它有一个非零返回代码。jar在我的Nexus存储库中,所以我想将其作为依赖项下载 我将它配置为使用maven exec插件和java目标(如中)执行,但它在与maven相同的JVM中执行,maven构建在调用System.exit时停止,因为它是 配置maven exec插件依赖项的一个非常好的特性是,它下载jar及其所有依赖项,因此不需要使用maven assembly插件将所有jar包含在可执行文件中Maven:如何在分叉JVM中执行依赖项?,maven,maven-exec-plugin,Maven,Maven Exec Plugin,我的存储库中有一个jar程序,用于验证项目中的一些文件。当验证失败时,它有一个非零返回代码。jar在我的Nexus存储库中,所以我想将其作为依赖项下载 我将它配置为使用maven exec插件和java目标(如中)执行,但它在与maven相同的JVM中执行,maven构建在调用System.exit时停止,因为它是 配置maven exec插件依赖项的一个非常好的特性是,它下载jar及其所有依赖项,因此不需要使用maven assembly插件将所有jar包含在可执行文件中 如何配置pom.xm
如何配置pom.xml以执行jar依赖项并在失败时正确停止?我解决了问题。此解决方案有很多优点: 不需要在运行它的机器中安装任何东西,无论是开发人员机器还是持续集成机器。 验证工具开发人员可以发布新版本,并将自动更新。 开发人员可以通过一个简单的参数将其关闭。 还解决了最初的问题:验证工具将在单独的进程中执行,因此maven进程在调用System.exit时不会中止。 下面是一个已注释的pom.xml:
你能更详细地说明你的问题到底是什么,因为通过execmaven插件执行依赖对我来说很奇怪吗?如果构建过程中需要它,请创建一个插件…?@khmarbaise:我想执行一个内部工具来验证代码。我设法运行了它exec:java,这是一个非常好的解决方案,因为我只需要将它放在我们的包存储库中,maven就会自动下载它及其所有依赖项。问题是它执行时没有分叉,system.exit将结束maven进程。我将在周一发布原始解决方案。我建议通过maven插件运行您的工具,该插件将解决您的所有问题…@khmarbaise,哪个插件?编写它只是为了将其正确集成到您的构建过程中…更干净。参数xml已被破坏here@Vadzim为什么它坏了?它对我有用。您必须使其适应您的系统。也许我能帮你适应。发布命令行调用如何。请尝试根据xsd进行验证。我想,对你有用的并不完全是这里引用的。
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>yourId</artifactId>
<version>1.0</version>
<properties>
<!--
Skip the validation executing maven setting the parameter below
mvn integration-test -Dvalidation.skip
-->
<validation.skip>false</validation.skip>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>My Validatior</id>
<phase>integration-test</phase> <!-- you can associate to any maven phase -->
<goals>
<goal>exec</goal> <!-- forces execution in another process -->
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable> <!-- java must be in your PATH -->
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
<skip>${validation.skip}</skip>
<arguments>
<argument>-classpath</argument>
<classpath/> <!-- will include your class path -->
<mainClass>com.company.yourpackage.AppMain</mainClass> <!-- the class that has your main file -->
<argument>argument.xml</argument> <!-- any argument for your executable -->
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<!-- Specify your executable jar here -->
<groupId>com.company.validator</groupId>
<artifactId>validatorId</artifactId>
<version>RELEASE</version> <!-- you can specify a fixed version here -->
<type>jar</type>
</dependency>
</dependencies>
</project>