【问题标题】:Why Maven Assembly Plugin does not include my project files in the jar with dependencies ?为什么 Maven Assembly Plugin 不将我的项目文件包含在具有依赖项的 jar 中?
【发布时间】:2014-05-21 17:50:30
【问题描述】:

我正在使用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>

我做错了什么?

【问题讨论】:

  • 试着看看那个答案stackoverflow.com/a/574650/1370062
  • 我没有工作,因为我已经按照答案配置了我的 pom.xml,但是仍然出现错误!
  • 同样的错误?
  • 您确定在类路径中有com.project.ServerStart
  • 你能再解释一下吗?你在类路径上是什么意思?我怎样才能确定呢?我正在使用 Ubuntu 13.04,您希望我将所有项目类添加到 $PATH 变量吗?

标签: java maven maven-assembly-plugin


【解决方案1】:

根据您在问题中包含的警告:

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

我猜你已经将pom.xml 中的packaging 设置为pom

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

【讨论】:

  • 这正是问题所在!
猜你喜欢
  • 2013-05-09
  • 2014-03-12
  • 2015-04-19
  • 1970-01-01
  • 2018-11-16
  • 2014-06-08
  • 1970-01-01
  • 2015-01-27
  • 2010-10-25
相关资源
最近更新 更多