为什么Maven Assembly Plugin不包含带有依赖项的jar中的项目文件?

时间:2014-05-21 08:31:22

标签: java maven maven-assembly-plugin

我使用maven assembly plug in打包我的项目及其所有依赖项,因此我可以运行一个简单的java -jar myproject.jar并能够运行该项目。但是,当我运行它时,它告诉我

Error: Could not find or load main class com.project.ServerStart

然后我解压缩.jar文件,发现程序集不包含我的项目文件,这太荒谬了!
打包项目时,我收到此警告

[WARNING] Cannot include project artifact: Amjar:amjar:pom:0.2; it doesn't have an associated file or directory.

这是我的插件配置

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <finalName>amjar-${project.version}</finalName>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>com.project.ServerStart</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>assemble-all</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

我做错了什么?

1 个答案:

答案 0 :(得分:10)

根据您提问中的警告:

[WARNING] Cannot include project artifact: Amjar:amjar:pom:0.2; it doesn't have an associated 

我猜你的packaging设置为pom.xml pom

如果您的模块只是打包一组依赖项或资源文件,这很好,但是,如果您还希望Maven创建一个包含您模块中的类的jar,则需要将packaging设置为{ {1}}。