maven 打包时将 jar 也导入jar项目

在 pom.xml 中添加代码

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.8</version>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <!-- 拷贝项目依赖包到lib/目录下 -->
              <outputDirectory>${project.build.directory}/lib</outputDirectory>
              <!-- 间接依赖也拷贝 -->
              <excludeTransitive>false</excludeTransitive>
              <!-- 带上版本号 -->
              <stripVersion>false</stripVersion>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!--      打包 独立 jar 插件-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>org.example.dazuoye.CodeDriver</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>

    </plugins>

  </build>

在右侧的 maven 工具栏选择 assembly:assembly 打包方式即可
image

作者:ko25891wan

出处:https://www.cnblogs.com/ko25891wan/p/17465832.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

备注:你可以在这里自定义其他内容,支持 HTML

posted @   小小的编程员  阅读(38)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
点击右上角即可分享
微信分享提示