Is there a way to get the core class path of a running Java program.
structure
D:/ |---Project |------bin |------src
I want to get the path as D:\Project\bin\ .
I tried System.getProperty("java.class.path"); but the problem is if I run like
java -classpath D:\Project\bin;D:\Project\src\ Main Output Getting : D:\Project\bin;D:\Project\src\ Want : D:\Project\bin
Is there any way to do this?
===== EDIT =====
There is a solution here
This is printed:
file:/C:/Users/Jon/Test/foo/Test.class
Note that most class files are compiled into JAR files, so this will not work in every case (hence the IllegalStateException ). However, you can find the JAR that the class contains using this method, and you can get the contents of the class file by substituting getResourceAsStream() instead of getResource() , and this will work if the class is on the file system or in the JAR.
java
Denim Datta Jul 09 '13 at 5:54 on 2013-07-09 05:54
source share