When I mvn clean package
the project and run it with java -jar target/project.jar
it throws an error that it cannot find some class from an external jar.
Steps taken
All external jars are in a folder of my project:
/jars
or/jars/morejars/
Adding the jars to the build path: In Eclipse I right click on
project
, go tobuild path
and selectadd external archives
. I can see that eclipse creates a library folder "referenced libraries" below the "Maven dependencies" folder. When I checkproject
->Properties
->Java Build Path
->Libraries
I can see all the imported jars.
Some of those external jars are described as <dependency>
(with <systemPath
) in pom.xml
, so they will not be seen in Referenced Libraries
but in Maven dependencies
(interestingly, the class that cannot be found when running my packaged project is in an external jar that doesn't reside in Referenced Libraries
but Maven dependencies
)
e.g.
<dependency>
<groupId>external.jar.groupid</groupId>
<artifactId>external.jar.artifactid</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/jars/external-jar.jar</systemPath>
</dependency>
Use the maven assembly plugin (as described here), this is my full
<build>
config:<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build>
Run
mvn clean package
->BUILD SUCCESS
java -jar target/project.jar
-> Cannot findsome.class
fromexternal.jar
Thanks for the help