简体   繁体   中英

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

实现您自己的ClassLoader ,可以简单地扩展URLClassLoader并将扩展目录的URL添加到classloader实例。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM