Sha*_*aun 17 java jar build embedded-jetty maven
我有一个多模块maven项目,其中一个模块用于分发.
Project \
| moduleA \
| moduleB \
| ...
| dist-module \
Run Code Online (Sandbox Code Playgroud)
该发行版包含一个我想轻松执行的可执行jar.但是,要执行它,我必须输入类似的内容:
java -jar dist-module/target/dist-module-1.0-SNAPSHOT-full-dist/myJar.jar
Run Code Online (Sandbox Code Playgroud)
简单地键入:
mvn exec:java \ OR
mvn exec:exec
Run Code Online (Sandbox Code Playgroud)
不幸的是,我找不到让java目标执行.jar的方法.exec目标实际上是这样做的,但是有一个问题:jar包含一个嵌入式jetty服务器,并且由于exec的工作方式(不使用与maven相同的JVM),服务器不会终止,除非我终止进程手动,这同样令人烦恼.
有关如何使用maven执行此操作的任何建议?
编辑:
为了澄清,该命令主要用于简单的手动烟雾测试; 读取日志输出并确保程序在其分发环境中正确启动.因此,它应该是一个阻塞调用,ctrl-c终止服务器和maven.
嵌入式服务器专门用于运行一些特定的应用程序,并不会自动重新加载它们.因此,不需要长时间独立于maven运行服务器.
use*_*755 28
mvn exec:java直接从目标下面的编译器输出运行应用程序/ - 无需从jar运行:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>uk.co.pookey.hibernate.App</mainClass>
<systemProperties>
<systemProperty>
<key>derby.stream.error.file</key>
<value>${basedir}/target/derby.log</value>
</systemProperty>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果你想用mvn exec运行jar:exec:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<!-- optional -->
<workingDirectory>/tmp</workingDirectory>
<arguments>
<argument>-jar</argument>
<argument>${basedir}/target/hibernate-derby-memory-${project.version}.jar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果您遇到jetty终止问题,我建议运行集成测试(或者不要先退出jetty主线程而不先终止jetty,或者只使用jetty的停止端口)!可以在后台运行JVM,让maven在测试后再次停止它.这有三个阶段:预集成测试,集成测试或集成后测试.您可以在http://docs.codehaus.org/display/MAVENUSER/Maven+and+Integration+Testing上阅读更多相关信息.使用jetty maven插件时,pom.xml配置可能会:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<!-- test start/stop: -->
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy-war</goal>
</goals>
<configuration>
<daemon>true</daemon>
<systemProperties>
<systemProperty>
<name>some.prop</name>
<value>false</value>
</systemProperty>
</systemProperties>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
您可以绑定maven antrun插件来执行任意命令,而不是将jetty maven插件绑定到这些阶段.