1

I have multiple runnable jar files. Each of these jar files references the same external jar file. When I try to export my runnable jar files individually with eclipse, each export creates a directory e.g. jar1_lib, jar2_lib. Each of these directories contains the same referenced jar file.

I want to have each of my runnable jar files reference a single directory which contains a single instance of the required external jar.

Is this possible?

Thanks in advance.

1 Answers1

0

Technically it is possible, but you will need to update source code of all projects which use this single jar file.

Consider JCL Framework

Below, there's sample code from this comment

JarClassLoader jcl = new JarClassLoader();  
jcl.add("myjar.jar"); //Load jar file  
jcl.add(new URL("http://myserver.com/myjar.jar")); //Load jar from a URL  
jcl.add(new FileInputStream("myotherjar.jar")); //Load jar file from stream  
jcl.add("myclassfolder/"); //Load class folder  
jcl.add("myjarlib/"); //Recursively load all jar files in the folder/sub-folder(s)  

JclObjectFactory factory = JclObjectFactory.getInstance();  

//Create object of loaded class  
Object obj = factory.create(jcl,"mypackage.MyClass");
Community
  • 1
  • 1