java - 在 Reactor 项目中的单个 Maven 构建中运行 Java 应用程序和 Web 应用程序

标签 java eclipse maven build-process

我有一个具有以下结构的 react 器项目

server
- pom.xml (parent) 
-- appserver (has a server socket)
-- webserver (connects to the socket in appserver and gets data)

appserver pom.xml 有一个 maven-exec-plugin,它运行我的 java 类 AppServer 中的 main 方法。

当我在最顶层(服务器)项目中运行目标验证时,我的构建陷入了 appserver - exec goal,并且永远不会继续构建/运行我的网络服务器。

理想情况下,我想首先运行我的应用程序服务器,然后在一次安装中运行我的网络服务器,或者验证在我最上面的项目上运行。

这是我的 appserver pom 中的 exec maven 插件配置。

<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> 

我知道以前也有人问过许多类似性质的其他问题,大多数答案都围绕着使用 antrun 插件的 shell 脚本,几乎所有问题都至少有 3/4 年的历史,我希望有更多的新解决方案现已提供独立于平台的方式。

最佳答案

不幸的是,没有比针对您的用例使用 maven-antrun-plugin 更好的解决方案了。 maven-exec-plugin可用于启动外部进程,无论是在与java相同的VM中目标或在具有 exec 的 fork 虚拟机中目标,但在这两种情况下,它都会受到阻碍;这意味着插件将等待执行完成。如前所述启动 Shell 脚本的可能解决方法 herehere在Linux环境下运行良好。但是,它不适用于您的情况,因为您需要支持多个环境。

maven-antrun-plugin ,您可以使用Exec任务并将 spawn 属性设置为 true。这将导致 Ant 在后台运行该任务。示例配置如下:

<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.runtime.classpath引用包含所有运行时依赖项的 Maven 类路径(有关详细信息,请参阅 here)。

关于java - 在 Reactor 项目中的单个 Maven 构建中运行 Java 应用程序和 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35437358/

相关文章:

java - Liferay 开发者客户端网络服务

java - 寻找 Eclipse 的替代品(或没有所有错误的运行 eclipse 的方法)

java - 使用 Optaplanner 7.0.0.Final 时出现 ClassNotFoundException org.reflections.Configuration

spring - 在 jsp 文件中使用 taglib 会抛出 500 错误

java - 输入数字进入下一行,但输入非数字时出现异常

java - repaint() 方法不会重新绘制我的屏幕

java - Java中卸载dll

java - 为什么我的离屏图像渲染不起作用?

c++ - Eclipse 中的枚举声明

java.lang.ClassNotFoundException : org. springframework.beans.factory.access.BeanFactoryReference