0

1.I already tried by wmic process get name,executablepath,processid|findstr pid. but the result is the path of java.exe rather than i expected.i want to get the java app's full path like test.jar's full path. xx.bat:

    %~d0
    cd %~dp0 
    java -jar test.jar 

2.java code:

    String path = "..../xx.bat"; 
    String cmd = "cmd /c start " + path.replaceAll(" ", "\" \""); 
    process = Runtime.getRuntime().exec(cmd); 

3.the question is: how can i get the java app named test full path.

star
  • 159
  • 1
  • 11
  • You have to remember, your `test.jar` is been executed by `java.exe`, so it's been passed to `java.exe` as a parameter. You could try using `System.getProperty("user.dir")` which will return the "working" directory, which based on your command line, should return the path the jar file is been executed within – MadProgrammer Oct 20 '15 at 00:47
  • im sure the test.jar is been executed,because i can get the `pid` of test.jar in java code. so i want get the test.jar full path by pid. – star Oct 20 '15 at 01:14
  • Yes, it's been executed, by `java.exe`, the Jar file itself is not executable, from a OS point of view – MadProgrammer Oct 20 '15 at 01:15
  • my point is that i just want a java app's full path of each java.exe in windows,which java app is running in windows. so the answer need system commands in windows. – star Oct 20 '15 at 01:43

1 Answers1

0

The location of the .class file for the currently executing class is given by

this.getClass().getProtectionDomain().getCodeSource().getLocation();
user207421
  • 305,947
  • 44
  • 307
  • 483
  • thank for your answer,however,i need to get the java app's full path which already is running ,actually , want the way to get path in another java app. – star Oct 20 '15 at 06:36
  • @star Then I suggest you say so in your question. – user207421 Oct 21 '15 at 01:47