Skip to content

Instantly share code, notes, and snippets.

@wayoda
Last active August 28, 2021 10:12
Show Gist options
  • Save wayoda/3d83ded3642e9531f731 to your computer and use it in GitHub Desktop.
Save wayoda/3d83ded3642e9531f731 to your computer and use it in GitHub Desktop.
Get the user.dir and codebase dir for a jar file invoked from the commandline
package org.wayoda.arduino;
import java.util.Properties;
import java.io.File;
public class GetSystemPath {
public GetSystemPath() {
Properties p=System.getProperties();
String userDir=p.getProperty("user.dir");
try {
File jarDir=new File(GetSystemPath.class
.getProtectionDomain()
.getCodeSource()
.getLocation()
.toURI().getPath());
File codeDir=jarDir.getParentFile();
System.out.println(" Current user dir is : '"+userDir+"'");
System.out.println(" Here is the jar-file : '"+jarDir+"'");
System.out.println("The directory of the jar-file : '"+codeDir+"'");
}
catch (Exception e) {
System.out.println(e);
}
}
public static void main(String [] argv) {
GetSystemPath gsp=new GetSystemPath();
}
}
Main-Class: org.wayoda.arduino.GetSystemPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment