简体   繁体   English

从Maven项目制作可执行JAR

[英]Make an executable JAR from a maven project

I have a question about using Apache Maven: I built a very simple Maven-based project. 我对使用Apache Maven有一个疑问:我建立了一个非常简单的基于Maven的项目。 This works fine so far. 到目前为止,这个工作正常。
Now I want to make an executable JAR file from my target file. 现在,我想从目标文件中生成一个可执行的JAR文件。 The problem here seems to be that the dependencies (external libraries) are not packaged together with my app. 这里的问题似乎是依赖项(外部库)没有与我的应用程序打包在一起。

I've already googled and found the maven-assembly-plugin. 我已经用谷歌搜索并找到了maven-assembly-plugin。 That actually does exactly what I want, but seems to be somewhat inflexible, since the dependencies are not automatically resolved and I can not specify file filters, etc. (or only with much effort over assembly.xml). 这实际上确实可以满足我的要求,但是似乎有点不灵活,因为依赖关系不会自动解决,并且我无法指定文件过滤器等(或仅在assembly.xml上花费了很多精力)。
What I really like is the solution of spring-boot-maven-plugin, so automatically determine all linked JAR files and put in a lib folder. 我真正喜欢的是spring-boot-maven-plugin的解决方案,因此可以自动确定所有链接的JAR文件并放在lib文件夹中。 Now my little project is not a Spring application, so Spring Boot might not be suitable for me, right? 现在我的小项目不是Spring应用程序,因此Spring Boot可能不适合我,对吧?
So what would interest me: Is there a way to get a similarly structured and executable JAR archive as spring-boot-maven-plugin builds? 因此,我感兴趣的是:有没有办法像spring-boot-maven-plugin那样获得结构和可执行的JAR归档文件?

Just use Maven Shade Plugin . 只需使用Maven Shade插件即可 It packages your dependencies inside your jar and you can specify the Java packages to exclude 它将依赖项打包在jar中,并且您可以指定要排除的Java包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM