How do you find absolute path of the Class currently in execution? The
Class may be a part of a jar, in which case, the path to the jar file
location is needed on individual systems.
1 comment(s) to... “question 13”
I here will post some java/j2ee questions found and the answers. Please feel free to comment also suggesting answers. This blog is dedicated for discussion and new thoughts. Please email new questions at jvquestions@gmail.com. I would post it on the blog.
1 comments:
The path to the jar file that is actually having the class which is
executed can be found out by below snippet of code.
public class TestOne{
public static void main(String[] args) {
Class cls = TestOne.class;
ProtectionDomain domain = cls.getProtectionDomain();
CodeSource source = domain.getCodeSource();
URL url = source.getLocation();
System.out.println(url);
}
}
Post a Comment