【问题标题】:I am running a maven project with package goal, it creates a .zip folder but no jar. Why is that?我正在运行一个带有包目标的 Maven 项目,它创建了一个 .zip 文件夹但没有 jar。这是为什么?
【发布时间】:2017-04-27 15:37:21
【问题描述】:

我正在运行一个带有包目标的 maven 项目,它创建一个 .zip 文件夹但没有 jar。这是为什么呢?

我猜我在 pom.xml 中留下了一个错误。谁能指出来?

   <project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/xsd/maven-4.0.0.xsd">
         <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>swt1</groupId>
<artifactId>iMage</artifactId>
<version>0.0.1-SNAPSHOT</version>
 </parent>
 <groupId>swt1.ub1.a1</groupId>
   <artifactId>2056751</artifactId>
 <packaging>pom</packaging>

 <build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
        </manifest>
      </archive>
    </configuration>
  </plugin>

  <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>2.17</version>
      <dependencies>
        <dependency>
          <groupId>com.puppycrawl.tools</groupId>
          <artifactId>checkstyle</artifactId>
          <version>...choose your version...</version>
        </dependency>
      </dependencies>
    </plugin>
</plugins>

非常感谢您提前提供的帮助。

【问题讨论】:

    标签: maven pom.xml executable-jar


    【解决方案1】:

    你的包装设置为pom,应该是jar 见https://maven.apache.org/pom.html

    <groupId>swt1.ub1.a1</groupId>
    <artifactId>2056751</artifactId>
    <packaging>jar</packaging>
    

    另一方面,如果这是一个聚合器项目(父 pom),您将需要一些模块,其中一个可能是您的 jar。

     <modules>
        <module>example-jar</module>
     </modules>
    

    这取决于你想要什么,如果你想要一个 jar 并且你的 src 结构是合适的请求一个 jar/

    【讨论】:

    • 但在这种情况下,值为 'jar' 的 'packaging' 无效。聚合器项目需要“pom”作为包装。那我该怎么办?
    • @ArminBeda 查看更新的答案,您需要查看一些示例项目。
    猜你喜欢
    • 2019-02-24
    • 1970-01-01
    • 2018-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 2020-05-16
    相关资源
    最近更新 更多