java get jar path

//this worked for me
File jarDir = new File(ClassLoader.getSystemClassLoader().getResource(".").toURI());

//this didn't work for me but it is often suggested
File jar = new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI());

4.4
5
M.Sukumar 125 points

                                    return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation()
    .toURI()).getPath();

4.4 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
get location of running jar file java file location of jar file java file get jar path java get jar file location get jar file path in java jar files location java -jar files location java -jar file location jar file location in java java getting location of jar java get directory of jar file get the location of jar file in java java get folder of jar java get path location of jar java getting jar location java get path to folder in jar java ger path of jar get currently running jar file file path java How to get the path of the currently running jar file java how to get path where is jar is located cant i get the path and run a file from inside a jar file? cant i get the path and run a file from a jar file? Get JAR Runner how to find the path of a jar Where can I find jar file? jar location in java java get jar location get jar file location java jar -uf jar path file how to get directory of jar java java jar runner where located how to get jar file location in java coding java.jar location get a file from directory of jar file java get location of jar get directory jar file path in java java get jar path how to get a directory that a .jar file is in from the .jar getProtectionDomain().getCodeSource() getprotectiondomain().getcodesource().getlocation().getpath() get base dir of jar get base file of jar java jar file location jar path java how to get jar location in java java get location of current jar java get directory of current jar get path of runned jar how to get jar file current directory java get path from jar file java jar does not recognize home directory java get directory where jar is running getting .jar path java java how to find file in folder the .jar is in java get directory of jar java get file from jar running directory java how to get running jar path in linux java how to get running jar path java get parent directory of jar java get a jar file java get the directort the jar is inside paths current directory java jar get curretn location of the jar java java get actual jar java get path of current jar java get jar file path java get the location of jar java get path of jar java get location of jar file
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source