加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 为什么Maven Assembly Plugin不包含带有依赖项的jar中的

发布时间:2020-12-14 05:47:27 所属栏目:Java 来源:网络整理
导读:我使用 maven assembly plug in打包我的项目及其所有依赖项,所以我可以运行一个简单的java -jar myproject.jar并能够运行该项目.但是,当我运行它时,它告诉我 Error: Could not find or load main class com.project.ServerStart 然后我解压缩.jar文件,发现程
我使用 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>

我究竟做错了什么 ?

解决方法

从您在问题中包含的警告中:
[WARNING] Cannot include project artifact: Amjar:amjar:pom:0.2; it doesn't have an associated

我猜你的pom.xml中的包装设置为pom.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读