Simon
Simon

Reputation: 17

Java Application loading external jar

I am about to program a java application that is able to load extended functionality from an external directory that contains extension .jar files. I tried to specify that external directory within the MANIFEST.MF file's Class-Path property but unfortunately (by Oracle's specification) loading .jar files using wildcards is not supported / prohibited.

Using the -classpath option does not work as long as there is a manifest file in the main application jar.

Does anyone have an Idea how I can solve this problem. I there another possibility to specify an external .jar directory (either by a configuration file/setting or within the program). Thanks

Upvotes: 0

Views: 191

Answers (2)

dikey
dikey

Reputation: 21

I always put external libs in a directory for jar aplications in this way:

   dir
   |-myapp.jar
   └ lib
      |-mylib.jar
      └ log4j-1.2.14.jar 

Then I list the in libs the MANIFEST.MF for my application:

Class-Path: lib/mylib.jar lib/log4j-1.2.14.jar

Upvotes: 0

Crazyjavahacking
Crazyjavahacking

Reputation: 9677

Implement your own ClassLoader, which could simply extend URLClassLoader and add the URL of the extension directory to the classloader instance.

Upvotes: 1

Related Questions