简体   繁体   English

如何使用具有外部依赖项的maven创建和运行可执行jar?

[英]How do I create and run an executable jar with maven that has external dependencies?

I have a jar plugin but it's not running because it isn't including the external dependencies in the jar. 我有一个jar插件,但未运行,因为它未在jar中包含外部依赖项。 I can't seem to figure out how to include these dependencies, I seem to be finding a bunch of different solutions that conflict with each other for some reason. 我似乎无法弄清楚如何包含这些依赖关系,我似乎正在发现一堆由于某种原因而相互冲突的不同解决方案。 I ideally would like it to run on systems without the need for any special maven commands. 理想情况下,我希望它可以在不需要任何特殊maven命令的系统上运行。

create maven pom.xml with 用以下命令创建Maven pom.xml

<packaging>jar</packaging>

By default it should not pack into your jar all dependent libraries. 默认情况下,它不应将所有依赖库打包到您的jar中。

<plugin>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <phase>install</phase>
       <goals>
        <goal>copy-dependencies</goal>
       </goals>
     <configuration>
       <outputDirectory>${project.build.directory}/lib</outputDirectory>
     </configuration>
 </execution>
 </executions>
</plugin>

What you are looking for is to build an über-jar. 您正在寻找的是建造一个über-jar。 The Maven Shade plugin can do that - http://maven.apache.org/plugins/maven-shade-plugin/ . Maven Shade插件可以做到这一点-http://maven.apache.org/plugins/maven-shade-plugin/ It even allows for renaming of classes. 它甚至允许重命名类。

暂无
暂无

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

相关问题 如何使用 Maven 创建具有依赖关系的可执行 JAR? - How can I create an executable JAR with dependencies using Maven? 如何使用Maven创建一个没有依赖关系的可执行jar? - How can I create an executable jar without dependencies using Maven? 如何使用 maven 和系统依赖项创建可执行的 jar? - How to create executable jar with maven and system dependencies? 如何使用 Gradle 和实现依赖项创建可执行的胖 JAR? - How do I create an executable fat JAR with Gradle with implementation dependencies? 如何在Eclipse中使用其他外部jar依赖项创建一个不可运行/不可执行的jar - how to create a not runnable/not executable jar with other external jar dependencies in Eclipse 如何使用Maven在jar的子文件夹中创建具有依赖项的可执行jar? - How can I create an executable jar with dependencies in sub folder in jar using Maven? 如何使用 Maven 为我的 webapp 创建可执行 jar? - How do I create an executable jar for my webapp with Maven? 如何使用 Maven 创建具有依赖项的不可执行 JAR? - How can I create a non-executable JAR with dependencies using Maven? 如何导出将在另一个Java项目中使用的jar以及jar使用的整个maven /外部依赖关系? - How do I export a jar that will be used in another Java project, along with the entire maven/external dependencies that the jar uses? 您如何创建然后在Intellij IDE(特别是Android Studio)中运行具有依赖项的可执行jar? - How do you create then run an executable jar with dependencies in Intellij IDEs, specifically Android Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM