0

I have a jar called x.jar

all of the jar's dependencies are placed inside the jar using maven-shade-plugin.

I also previously tried using maven-assembly-plugin or maven-one-jar-plugin

in y.jar I try using a Class-loader like presented in the following question: How should I load Jars dynamically at runtime?

when i load x.jar into y.jar in runtime, it cannot find the library dependencies inside of y.jar, so it crashes.

how do i load x.jar in a way that it works as a class library with all of its dependencies?

EDIT:

  • running the library statically from another project works fine and all of the dependencies work ok.
  • adding the dependencies into y.jar solves it, but i do not want them there.
  • i do not want y.jar to know about x.jar dependencies
Amir.F
  • 1,911
  • 7
  • 29
  • 52
  • You build the classloader such that it lists all the jars needed, including the extra jars inside x.jar. – Andreas Jun 07 '17 at 14:42
  • but then x.jar needs to know all of y.jar dependencies – Amir.F Jun 07 '17 at 14:55
  • Why would code in x.jar need to access dependencies of y.jar, when all of the dependencies of x.jar are placed inside x.jar? Anyway, just make the current classloader the parent of the dynamic classloader for x.jar. – Andreas Jun 07 '17 at 15:00
  • sorry i mean i don't want y.jar to start and handle all of x.jar dependencies. what do you mean current class loader as parent? i create a URLClassLoader that loads a class from x.jar – Amir.F Jun 07 '17 at 15:05
  • you mean this - URLClassLoader child = new URLClassLoader(path, this.getClass().getClassLoader()); if so it does not work to fix it – Amir.F Jun 07 '17 at 15:12
  • Why would it? That just ensures that .jars already in the classpath for `y.jar` is also available for `x.jar`, but it doesn't add all those extra jars inside `x.jar`. ***You*** have to do that, by listing them when building the dynamic classloader. – Andreas Jun 07 '17 at 15:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/146093/discussion-between-amir-f-and-andreas). – Amir.F Jun 07 '17 at 17:00

0 Answers0