Is it possible to get the path to my .class file containing my main function from within main?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note that most class files are assembled into JAR files so this won’t work in every case (hence the
IllegalStateException). However, you can locate the JAR that contains the class with this technique, and you can get the content of the class file by substituting a call togetResourceAsStream()in place ofgetResource(), and that will work whether the class is on the file system or in a JAR.