0

I have a project multimodule, every module is defined as a jar, and every module, has some dependency like:

<dependency>
            <groupId>it.demker.rapdev.be.esb</groupId>
            <artifactId>CR_RAPDEV_BE_PRODO_DEBICLIENT_V1</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <type>jar</type>
</dependency>

As you can see there is no:

<scope>provided</scope>

So after

mvn clean compile package

If I open the jar file produced, i'm going to find the jar CR_RAPDEV_BE_PRODO_DEBICLIENT_V1 but there isn't any jar file, (inside my jar)?

How is that possible? For what I know if I don't specify provided, maven should be put the dependency inside the jar file.

fraaanz
  • 51
  • 11
  • 3
    Your understanding is wrong, maven will not generate a jar with jars in it. Unless you have a plugin that does that for you, but by default this doesn't happen. – M. Deinum Feb 21 '23 at 14:23
  • but if it was a war, I will have jar inside the war! if not put provided; where is written on maven doc that .... – fraaanz Feb 21 '23 at 14:43
  • 1
    Correct but war is something different from a simple jar. A war has a defined structure and libraries should go in `/WEB-INF/lib` this is what the `maven-war-plugin` takes care of. – M. Deinum Feb 21 '23 at 14:45
  • If the project is building sucessfully, there must be something that excludes the artifact. Try to call mvn with -X flag to debug – codigocaballer Feb 21 '23 at 15:27
  • @codigocaballer Building is not the same as running. – Dave Newton Feb 21 '23 at 22:36

2 Answers2

1

Nope, if you don't specify provided, maven will not put the jar dependency in a jar file.

By the way, the default Java ClassLoader doesn't support to load a jar in jar.
See Adding Classes to the JAR File's Classpath :

Note: The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over Internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

If you want to have all dependency in your jar, a solution could be to use maven Shade plugin to create Uber Jar.

sbernard
  • 444
  • 3
  • 16
1

JARs do not contain their dependencies unless you explicitly use something like Maven Assembly Plugin or Maven Shade Plugin.

WARs always contain their dependencies if they are not provided or otherwise excluded.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142