【问题标题】:How to run maven build when launching Intellji-Idea JUnit test configuration?启动 Intellij-Idea JUnit 测试配置时如何运行 maven build?
【发布时间】:2015-11-25 12:27:06
【问题描述】:

运行 JUnit 配置时,下面的断言失败。

String dirName = System.getProperty("dataDir");
Assert.assertNull(dirName);

pom.xml中描述的参数dataDir

<systemProperties>
                    <property>
                        <name>dataDir</name>
                        <value>src/main/resources/data</value>
                    </property>
</systemProperties>

【问题讨论】:

    标签: java maven intellij-idea junit


    【解决方案1】:

    maven-surefire-plugin 已弃用系统属性构造 http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html

    添加属性的正确方法是

    <systemPropertyVariables>
                    <propertyName>propertyValue</propertyName>
                    <buildDirectory>${project.build.directory}</buildDirectory>
        </systemPropertyVariables>  
    

    【讨论】:

      【解决方案2】:

      试试这个:

      <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19</version>
          <configuration>
            <systemPropertyVariables>
              <propertyName>dataDir</propertyName>
              <buildDirectory>src/main/resources/data</buildDirectory>
             </systemPropertyVariables>
          </configuration>
        </plugin>
      </plugins>
      

      如果你需要复制库,你可以这样做

      <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-dependency-plugin</artifactId>
                  <executions>
                      <execution>
                          <id>copy-dependencies</id>
                          <phase>prepare-package</phase>
                          <goals>
                              <goal>copy-dependencies</goal>
                          </goals>
                          <configuration>
                              <outputDirectory>${project.build.directory}/project/WEB-INF/lib</outputDirectory>
                              <overWriteReleases>false</overWriteReleases>
                              <overWriteSnapshots>false</overWriteSnapshots>
                              <overWriteIfNewer>true</overWriteIfNewer>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
      

      【讨论】:

        猜你喜欢
        • 2014-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多