mvn exec:java 直接从 target/ 下面的编译器输出运行应用程序 - 无需从 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>
如果你想用 mvn exec:exec 运行 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>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>
如果您在码头终止时遇到问题,我建议您运行集成测试(或者只是不要在没有先终止码头的情况下退出码头主线程,或者只是使用码头的停止端口)!可以在后台运行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>
您可以将 maven antrun 插件绑定到这些阶段,而不是将 jetty maven 插件绑定到这些阶段,以执行任意命令。