如何将所有依赖项放在runnable jar的单独文件夹中?

编程入门 行业动态 更新时间:2024-10-27 22:29:43
本文介绍了如何将所有依赖项放在runnable jar的单独文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 mvn package 来创建一个可运行的jar,其中包含所有依赖项,运行正常。 但我更喜欢将所有外部依赖项打包在一个单独的文件夹中。那么我需要改变什么呢?

I'm using mvn package to create a runnable jar with all dependencies packed inside, which runs fine. But I'd prefer to have all external dependencies packed in a separate folder. What would I have to change therefore?

<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>my.MainApp</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>

推荐答案

使用 maven-dependencies -plugin 指定 copy-dependencies 执行的输出目录。

Use the maven-dependencies-plugin to specify an output directory for the copy-dependencies execution.

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.5.1</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib/</outputDirectory> </configuration> </execution> </executions> </plugin>

更新:

要让jar知道在哪里找到 lib 文件夹,您可以将其指定为 Class-Path 清单中的值使用 maven-jar-plugin

To let the jar know where to find the lib folder, you can specify this as a Class-Path value in the manifest using the maven-jar-plugin

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>foo.bar.MainClass</mainClass> </manifest> </archive> </configuration> </plugin>

希望这会有所帮助。

更多推荐

如何将所有依赖项放在runnable jar的单独文件夹中?

本文发布于:2023-11-14 16:46:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:放在   如何将   文件   夹中   runnable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!