使用Exec Maven插件分叉Java,而不使用`exec`目标 [英] Forking Java using the Exec Maven Plugin, without using the `exec` goal

查看:71
本文介绍了使用Exec Maven插件分叉Java,而不使用`exec`目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档:

  1. exec:exec在单独的进程中执行程序和Java程序.
  2. exec:java在同一VM中执行Java程序.
  1. exec:exec execute programs and Java programs in a separate process.
  2. exec:java execute Java programs in the same VM.

我想派生一个Java程序.我已经在exec:java中使它工作了,但是那不是分叉的.因此,显而易见的举动是将目标更改为exec.问题是,exec的语法与java的语法完全不同.它没有像includeProjectDependenciesincludePluginDependencies这样的标签.是否有我可以使用的插件,例如#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.

推荐答案

还可以使用导出几个类路径,涵盖了编译/运行时/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`目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆