Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependent classes missing in jar when using maven compile scope

Tags:

maven

My java project name is tmcloud, which using maven3, and in the pom.xml file I used the following dependency:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.7</version>
    <scope>compile</scope>
</dependency>

I thought that because of I used maven compile scope, the classes in commons-lang3 would be included in my final jar tmcloud-1.1.jar when I used command maven clean install, but I didn't find any classes of commons-lang3 in tmcloud-1.1.jar.

like image 528
Jack Avatar asked Jun 23 '26 22:06

Jack


1 Answers

maven doesn't include the dependencies in the jar by default. The dependencies are set to be available on the classpaths of your project.

If you want to have a self containing jar, that includes the dependant jars, you will have to use a plugin like the maven-shade-plugin.

like image 88
taygetos Avatar answered Jun 27 '26 13:06

taygetos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!