【问题标题】:using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was marked for inclusion在创建 jar:test-jar 时使用 maven pom 有时它说 JAR 将为空 - 没有内容被标记为包含
【发布时间】:2014-09-25 15:26:55
【问题描述】:

jar:test-jar 使用测试类创建 jar 时有时会说:

JAR 将为空 - 没有内容被标记为包含!

Test-jar 不包含任何测试类。但有时会使用所有测试类创建正确的测试 jar。

我需要在我的 pom 中提到什么才能在没有测试类的情况下运行测试模块 jar(仅编译)

关于 maven pom 需要什么 maven 命令

【问题讨论】:

  • 其实这个问题没有问题
  • 你真的要手动拨打jar:test-jar吗?
  • yes.from eclipse runco​​nfig-->在目标字段中我输入了 jar:test-jar 然后运行

标签: java maven jar


【解决方案1】:

如果您的输出目录中没有已编译的类,则可能会发生这种情况。见testClassesDirectory

例如,如果您运行mvn install(这也会触发compile 阶段)然后mvn jar:test-jar,您将获得带有测试类的jar。但是如果你运行mvn clean 然后mvn jar:test-jar 你会得到关于空jar 的消息,因此生成的jar 将是空的。

【讨论】:

  • thank you.but 甚至我的 pom install 有时也会给所有主要类 jar 有时没有。你能给我提供如你所说的生成 jar 的示例 pom(测试和具有依赖关系的主要类)
  • @user3863263 我认为这不是一个好主意。也许你可以分享你的 pom.xml。此外,始终考虑通过原型创建新项目以确保项目结构正确
  • stackoverflow.com/questions/24977602/… 是我的 pom 所在的链接。
【解决方案2】:

我得到了答案:

mvn clean install -DskipTests

Add this in your pom.xml

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
  </plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 2013-11-05
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多