return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation()
.toURI()).getPath();
Replace “MyClass” with the name of your class.
Obviously, this will do odd things if your class was loaded from a non-file location.
Related Contents:
- “Invalid signature file” when attempting to run a .jar
- Running JAR file on Windows
- How to run a class from Jar which is not the Main-Class in its Manifest file
- Creating runnable JAR with Gradle
- What causes “Unable to access jarfile” error?
- Execute another jar in a Java program
- How to make an executable JAR file?
- Visual Studio Code, Java Extension, how to add a JAR to classpath?
- NoClassDefFoundError while trying to run my jar with java.exe -jar…what’s wrong?
- Why is my URI not hierarchical? [duplicate]
- Reference jars inside a jar
- Including dependencies in a jar with Maven
- Find a class somewhere inside dozens of JAR files?
- What causes java.lang.IncompatibleClassChangeError?
- What version of javac built my jar?
- How to include jar files with java file and compile in command prompt
- How to use classes from .jar files?
- How to get names of classes inside a jar file?
- How to update PATH variable permanently from Windows command line?
- How to build a jar using maven, ignoring test results? [duplicate]
- How do I put all required JAR files in a library folder inside the final JAR file with Maven?
- What’s the best way to distribute Java applications? [closed]
- How to add native library to “java.library.path” with Eclipse launch (instead of overriding it)
- How to run .jar file by double click on Windows 7 64-bit?
- How to download sources for a jar with Maven?
- Why has it failed to load main-class manifest attribute from a JAR file?
- Java creating .jar file
- How to locate the Path of the current project directory in Java (IDE)?
- How do I create an executable fat JAR with Gradle with implementation dependencies?
- How to search for a string in JAR files
- How to make a JAR file that includes DLL files?
- How to pass system properties to a jar file
- Finding unused jars used in an eclipse project
- How to build JARs from IntelliJ IDEA properly?
- How to read a file from jar in Java?
- How do I create executable Java program? [duplicate]
- Remove project .jars from project explorer view in Eclipse
- Android Library Gradle release JAR
- How to create jar file with package structure?
- How to create my own java library(API)?
- Differences between jar and war in Spring Boot?
- Where to put the external jars? [duplicate]
- Set folder for classpath [duplicate]
- How to find which jars and in what order are loaded by a classloader?
- Maven JAR Plugin 3.0.2 Error: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them
- Where can I download the jar for org.apache.http package?
- Python: How can I execute a jar file through a python script
- Can you tell on runtime if you’re running java from within a jar?
- How can I edit a .jar file? [duplicate]
- Eclipse: How to build an executable jar with external jar?