问题描述
我有一个具有以下结构的反应堆项目
I have a reactor project with the following structure
server
- pom.xml (parent)
-- appserver (has a server socket)
-- webserver (connects to the socket in appserver and gets data)
应用服务器 pom.xml
有一个 maven-exec-plugin
,运行主方法在我的java类 AppServer
中。
The appserver pom.xml
has a maven-exec-plugin
that runs the main method in my java class AppServer
.
当我在最顶层(服务器)项目中执行目标验证时,我的构建将停留在appserver - exec目标中,从不继续构建/运行我的Web服务器。
When I run goal verify in my topmost (server) project my build gets stuck at appserver - exec goal and never proceeds to building / running my webserver.
理想情况下,我想首先运行我的应用服务器,然后在单个安装中验证我的网络服务器,或验证我的最顶级项目运行。
Ideally I would like to run my appserver first and then my webserver in a single install or verify run on my top most project.
这是我的appserver pom中的exec maven插件配置。
Here is the exec maven plugin configuration in my appserver pom.
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>somepackage.AppServer</mainClass>
</configuration>
我知道许多其他类似性质的问题已经被问过,大多数答案围绕着shell脚本与antrun插件,几乎所有的至少3/4岁,我希望有一个更多的平台独立方式可用的新解决方案现在可用。
I am aware that many other questions of similar nature have been asked before and most answers revolve around use of shell scripts with antrun plugin and almost all of them atleast 3 / 4 years old and I hope there is new solution in a more platform independent manner available now.
推荐答案
不幸的是,与使用 maven-antrun-plugin
的用例相比,没有更好的解决方案。 目标,或者在带有目标,但在这两种情况下,它将被阻止;这意味着插件将等待执行完成。 和在Linux环境中运行良好。但是,由于您需要支持多种环境,因此您无法使用。
There are unfortunately no better solutions than using the maven-antrun-plugin
for your use-case. maven-exec-plugin
can be used to launch an external process, either in the same VM with the java
goal or in a forked VM with the exec
goal, but in both cases, it will be blocking; meaning that the plugin will wait for the execution to finish. The possible work-around of starting a Shell script as mentioned here and here works well in Linux environment. It won't work in your case however because you need to support multiple environments.
使用,您可以使用任务,并将 spawn
属性设置为真
。这将导致Ant在后台运行任务。示例配置将是:
With the maven-antrun-plugin
, you can use the Exec task and set the spawn
attribute to true
. This will cause Ant to run the task in the background. A sample configuration would be:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase> <!-- a lifecycle phase --> </phase>
<configuration>
<target>
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<exec executable="java" spawn="true">
<arg value="-classpath"/>
<arg value="${runtime_classpath}"/>
<arg value="somepackage.AppServer"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
请注意,这使用来引用包含所有内容的Maven类路径运行时依赖关系(有关详细信息,请参阅)。
这篇关于在反应堆项目中的单个maven构建中运行java应用程序和Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!