run a java application and a web application in a single maven build within a reactor project

谁说胖子不能爱 提交于 2019-12-07 08:29:30
Tunaki

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.

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>

Note that this uses the maven.runtime.classpath to refer to the Maven classpath containing all runtime dependencies (see here for more info).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!