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 插件绑定到这些阶段。