R
raphfrk
Is there a way to get the path of the jar file that was passed on the command line?
java -jar <some path>
java -jar <some path>
You could try
RuntimeMXBean rtmxb = ManagementFactory.getRuntimeMXBean();
List<String> inArgs = rtmxb.getInputArguments();
although the documentation seems to suggest that what is actually
passed to the Runtime bean is dependent on the particular implementation
of the jvm you happen to be using.
Is there a way to get the path of the jar file that was passed on the command line?
java -jar <some path>
Is there a way to get the path of the jar file that was passed on the command line?
You can use -cp to specify the classpath or fully qualify the jar
name.
http://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file
Gives some good advice
The solution
String path =
Test.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = URLDecoder.decode(path, "UTF-8");
Works for me and gives me the path to the jar file containing the class
that contains the above code.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.