1, use current path
Execute Java command before the CD enters the directory where the Java command is located, the program should be the system Properties user.dir or through the new File (".") Fetch path
2, use relative path
System.getenv ("Java_home")/bin/java.exe
3, increase environment variable
Before executing JAVA, Add an environment variable to the bat or shell, and under Unix remember export
//windows:set proc_path=d:\jdk1.6.0_18\bin\javaw.exe
//unix: export proc_path=d:\jdk1.6.0_18\bin\javaw.exe
System.out.println (system.getenv ("Proc_path"));
4, SIGAR process path based on process ID
/*1), taking the current process Id*///[email protected] [email protected] Computer name String pid = managementfactory.getruntimemxbean (). GetName ();//@ before the process Idpid = pid.substring (0, pid.indexof (' @ ')),/*2), process command path based on process ID d:\jdk1.6.0_18\bin\javaw.exe*/ Sigar sigar = new sigar ();//http://www.oschina.net/p/sigarsystem.out.println ( Sigar.getprocexe (PID). GetName ()); System.out.println (Sigar.getprocargs (PID) [0]);
Java Fetch process path method