java - JRE not using classpath specified by manifest file of runnable jar -


first post, sorry poor formatting. have java program developed in eclipse. exported program jar (myjar.jar), , put of external jars program depends on folder called lib lives in same location myjar.jar. in order set classpath have manifest file following format:

main-class: exe.mymain class-path: lib/jar_1.jar lib/jar_2.jar ... lib/jar_n.jar manifest-version: 1.0 

however, when attempt run program using "java -jar myjar.jar" classes jars live in lib not being loaded (i'm getting classnotfoundexception) . used following code in program print classpath:

classloader cl = classloader.getsystemclassloader(); url[] urls = ((urlclassloader)cl).geturls(); for(url url:urls){     system.out.println(url.getfile()); } 

and when run code classpath "myjar.jar".

i have 2 questions:

1.) above code give me classpath jre @ run time, or being given address of main class?

2.) given above code indeed give me classpath jre @ run time, doing wrong?

please feel free ask more information, , happily provide need.

what doing sounds correct.

for reason class-path entry in manifest not show when inspecting classpath (e.g. here , here; examples use property "java.class.path" testing shows classloader.geturls() behaves same). should still searched classes though. don't know how obtain true classpath includes class-path entry manifest.

the first thing i'd check file meta-inf/manifest.mf inside myjar.jar matches manifest created. can open myjar.jar renaming have .zip file extension.

i tried replicate problem classes in lib/jar_1.jar loaded me, if meta-inf/manifest.mf correct i'll describe did in detail can find doing differently.

edit:

here steps used:

  1. create new directory called "experiment". following steps done in directory.

  2. create new directories called "jar_1", "lib", , "exe"

  3. create file called "classinjar1.java" in directory "jar_1" following content:

    package jar_1;  public class classinjar1 {     public static void method() {         system.out.println("hello classinjar1");     } } 
  4. run javac jar_1/classinjar1.java

  5. run jar cf lib/jar_1.jar jar_1/classinjar1.class

  6. create file called "mymain.java" in directory "exe" following content:

    package exe;  import java.net.*; import jar_1.classinjar1;  public class mymain {     public static void main(string[] args) {         classloader cl = classloader.getsystemclassloader();         url[] urls = ((urlclassloader) cl).geturls();         (url url : urls) {             system.out.println(url.getfile());         }         classinjar1.method();     } } 
  7. run javac exe/mymain.java

  8. create file called "manifest" in "experiment" directory following content:

    main-class: exe.mymain     class-path: lib/jar_1.jar lib/jar_2.jar     manifest-version: 1.0 
  1. run jar cfm myjar.jar manifest exe/mymain.class

  2. run java -jar myjar.jar

output:

/.../experiment/myjar.jar hello classinjar1 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -