Source: http://blog.csdn.net/magi1201/article/details/18731581
Java Web Engineering, sometimes you need to manually read classpath the following configuration file, here to summarize a bit of reading the classpath path, share.
Method One:
String Path = Test.class.getResource ("/"). ToString (); SYSTEM.OUT.PRINTLN ("path =" + path);
This method has no problem under Tomcat and can be taken to web-inf/classes
Path = file:/home/ngidm_db2/as_tomcat7_0_29/webapps/ngidm/web-inf/classes/
But after changing the WebLogic, we take the
Path = file:/oracle/weblogic/oracle/middleware/oracle_home/user_projects/domains/base_domain/
Under the WebLogic, failed to get the classes path.
Method Two:
String path2 = Thread.CurrentThread (). Getcontextclassloader (). GetResource ("/"). GetPath (); System.out.println ("path2 =" + path2);
Under Tomcat and WebLogic, it is advisable to go to the classes path
path2 =/oracle/weblogic/oracle/middleware/user_apps/ngidm/web-inf/classes/path2 =/home/ngidm_db2/as_tomcat7_0_29 /webapps/ngidm/web-inf/classes/
Therefore, we recommend that we use more
Thread.CurrentThread (). Getcontextclassloader (). GetResource ("/"). GetPath ();
Gets the classpath path, and Method 2 takes the Classpath without the file: prefix, which can be used directly.
Get classpath path in Java code