如何防止mvn jetty:从执行测试阶段开始运行?

tpu*_*nen 4 java maven-2 jetty maven-jetty-plugin

我们在生产中使用MySQL,在Derby中使用单元测试.我们的pom.xml在测试之前复制了derby版本的persistence.xml,并在prepare-package阶段将其替换为MySQL版本:

 <plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.3</version>
  <executions>
   <execution>
    <id>copy-test-persistence</id>
    <phase>process-test-resources</phase>
    <configuration>
     <tasks>
      <!--replace the "proper" persistence.xml with the "test" version-->
      <copy
       file="${project.build.testOutputDirectory}/META-INF/persistence.xml.test"
       tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
       overwrite="true" verbose="true" failonerror="true" />
     </tasks>
    </configuration>
    <goals>
     <goal>run</goal>
    </goals>
   </execution>
   <execution>
    <id>restore-persistence</id>
    <phase>prepare-package</phase>
    <configuration>
     <tasks>
      <!--restore the "proper" persistence.xml-->
      <copy
       file="${project.build.outputDirectory}/META-INF/persistence.xml.production"
       tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
       overwrite="true" verbose="true" failonerror="true" />
     </tasks>
    </configuration>
    <goals>
     <goal>run</goal>
    </goals>
   </execution>
  </executions>
 </plugin>
Run Code Online (Sandbox Code Playgroud)

问题是,如果我执行mvn jetty:run它将在启动jetty之前执行测试persistence.xml文件复制任务.我希望它使用部署版本运行.我怎样才能解决这个问题?

mat*_*t b 6

尝试在命令行中添加参数-Dmaven.test.skip = true或-DskipTests = true.例如

mvn -DskipTests=true jetty:run ...
Run Code Online (Sandbox Code Playgroud)

但是不确定这是否会跳过进程测试资源阶段.

有关跳过测试的更多信息,请参阅Surefire插件文档.