java - 如何防止mvn jetty :run from executing test phase?

标签 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>

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

最佳答案

尝试添加参数 -Dmaven.test.skip=true or -DskipTests=true in the command line .例如

mvn -DskipTests=true jetty:run ...

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

有关跳过测试的更多信息 is available in the Surefire plugin documentation .

关于java - 如何防止mvn jetty :run from executing test phase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3044867/

相关文章:

ssl - 如何让 Jetty 9 在访问 keystore 时忽略 keepass?

java - 音乐 "database"有 3 个类别;如何在SongDatabase类中存储信息

java - 连续运行插件处理程序

java - 从操作栏菜单项捕获用户输入

maven-2 - 使用 Maven Jetty 插件部署 war 时获取 FileNotFoundException

java - 在 Eclipse 中自动导入新的 Maven 模块

带有 jetty-maven-plugin 和 cdi 的 Maven 项目无法正常工作

java - 如何跨多个 IntelliJ 项目使用公共(public)源代码?

maven-2 - 从另一个 maven install 命令触发 maven install 命令

ruby-on-rails - 仅允许将Openshift应用程序与另一个应用程序连接