问题描述
从文档:
-
exec:exec
在单独的进程中执行程序和Java程序. -
exec:java
在同一VM中执行Java程序.
exec:exec
execute programs and Java programs in a separate process.exec:java
execute Java programs in the same VM.
我想派生一个Java程序.我已经在exec:java
中使它工作了,但是那不是分叉的.因此,显而易见的举动是将目标更改为exec
.问题是,exec
的语法与java
的语法完全不同.它没有像includeProjectDependencies
,includePluginDependencies
这样的标签.是否有我可以使用的插件,例如#1,它可以分叉,但是语法方便,例如#2? IMO#2应该仅具有<fork>true</fork>
配置.
I want to fork a java program. I've already got it working in exec:java
but that doesn't fork. So the obvious move is to change the goal to exec
. Problem is, the syntax for exec
is pretty different from the syntax of java
. It doesn't have tags like includeProjectDependencies
, includePluginDependencies
, etc. Is there a plugin I can use that is like #1 in the sense that it forks, but has a convenient syntax like #2? IMO, #2 should just have a <fork>true</fork>
configuration.
推荐答案
还可以使用 maven-antrun-plugin .此插件导出几个类路径,涵盖了编译/运行时/test范围以及插件依赖项.
It's also possible to spawn a Java process from Maven with the maven-antrun-plugin. This plugin exports several classpaths covering the compile/runtime/test scopes, as well as the plugin dependencies.
使用编译和插件依赖项在单独的进程中执行类将因此如下:
Executing a class in a separate process with the compile and plugin dependencies would thus look like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<java classname="com.example.MainClass" fork="true">
<classpath>
<path refid="maven.compile.classpath"/>
<path refid="maven.plugin.classpath"/>
</classpath>
</java>
</target>
</configuration>
</plugin>
这是用mvn antrun:run
而不是exec:exec
执行的.
这篇关于使用Exec Maven插件分叉Java,而不使用`exec`目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!