1

How to add one package with all classes and subpackage from provided dependency into the Jar.

I have got dependency like :

<dependency>
  <groupId>com.a</groupId>
  <artifactId>dependencyA</artifactId>
  <scope>provided</scope>
</dependency>

What I want to achieve is to add all classes and subpackage into jar file. For example Is there any plugin that allow me to specify which package should be added something like:

<include>com.a.package.*</include>

As a result, I expect that all classes under package com.a.package.* from dependencyA would be added into jar.

MartenCatcher
  • 2,713
  • 8
  • 26
  • 39
Łukasz Woźniczka
  • 1,625
  • 3
  • 28
  • 51
  • Have you tried using the Maven shade plugin? BTW: Your approach sounds strange, because `provided` dependencies should be provided by the environment, so you do not need to copy classes from there. – J Fabian Meier Jan 23 '20 at 10:32
  • @JFMeier yes I know your point. This is a specific case, I can't use whole library but just subpackage. I was trying to use shade plugin but didn't work, don't know if it is possible to specify which dependency and which package should be copied by plugin. – Łukasz Woźniczka Jan 23 '20 at 10:44
  • See https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html . It would be great if you can add to the question _why_ you can use only the package, not the whole library. – J Fabian Meier Jan 23 '20 at 12:27

1 Answers1

-1

You can't as you're defining a dependency, so your application needs that JAR fully, but you only import some packages, those what you need, so the JVM will only load those ones.

Carlos
  • 67
  • 5