- Get current running class dir path
String jarOrBuildClassDir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
It will return 'build/classes/main' if you run it on IDE
/Users/demo/workspace/MyDemo/build/classes/main/
It will return the location of 'jar' file which the class archived if you run it in a jar file
/Users/demo/workspace/MyDemo/install/MyDemo/lib/MyDemo.jar
URL xslFileURL = getClass().getResource("/com/demo/test.xsl")
It will return 'build/resources/main' if you run it on IDE
/Users/demo/workspace/MyDemo/build/resources/main/com/demo/test.xsl
It will return the location of 'jar' file which the class archived if you run it in a jar file
file:/Users/demo/workspace/MyDemo/install/MyDemo/lib/MyDemo.jar!/com/demo/test.xsl
No comments:
Post a Comment