[英]How to build an maven executable jar with external jar library?
I am trying to build jar file of my app based on Maven. 我正在尝试基于Maven构建我的应用程序的jar文件。 So I need to not include external jar library's to my build.
因此,我不需要在我的构建中包括外部jar库。 I need that my app gives this external dependency in runtime from local maven repository or from local folder, those will contain these external libraries.
我需要我的应用在运行时从本地Maven存储库或本地文件夹中提供此外部依赖关系,这些将包含这些外部库。 I configure my pom file for this dependency like this:
我为这种依赖关系配置pom文件,如下所示:
<profiles>
<profile>
<id>compile</id>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>some.artifact</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</profile>
and trying to run this jar with this prefix -Pcompile
. 并尝试使用此前缀
-Pcompile
运行此jar。 I am using this answer . 我在用这个答案 。
But in the runtime, when I am trying to execute a method, that using this external library, I've got java.lang.NoClassDefFoundError
with the name of my class from my external library. 但是在运行时中,当我尝试执行一个方法时,使用此外部库,我从外部库中获得了带有类名的
java.lang.NoClassDefFoundError
。
So how I can make a build that will use external jar libraries from local storage? 那么,如何制作将使用本地存储中的外部jar库的构建?
So i found the solution to store jars outside the final maven build. 因此,我找到了在最终的Maven版本之外存储jar的解决方案。 I was just need to add this jar to classpath with correct path.
我只需要将此jar添加到具有正确路径的classpath中即可。 For this i add this to pom.xml:
为此,我将其添加到pom.xml中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
<mainClass>your.mainClass</mainClass>
</manifest>
<manifestEntries>
<Class-Path>project-0.0.1-SNAPSHOT.lib/some.lib-1.1.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.