Reputation: 789
I am trying to build jar file of my app based on Maven. So I need to not include external jar library's to my build. 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. I configure my pom file for this dependency like this:
<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
. 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.
So how I can make a build that will use external jar libraries from local storage?
Upvotes: 2
Views: 5595
Reputation: 789
So i found the solution to store jars outside the final maven build. I was just need to add this jar to classpath with correct path. For this i add this to 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>
Upvotes: 1