我想通过从java代码中向jar文件传递两个参数来启动jar文件,我尝试的是:
File jarFile = new File("path/to/jar/file");
if ((jarFile).exists()) {
String[] command = new String[5];
command[0] = "java.exe";
command[1] = "-jar";
command[2] = jarFile + "";
command[3] = "arg1";
command[4] = "arg2";
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
} else {
System.out.println("File is not available");
}对于启动jar来说,代码是完美的,但是我想使用32位JVM启动jar文件,因为我的驱动程序只有32位。
我的机器包含32位和64位JVM,为了使用32位JVM启动jar,我可以使用硬编码的java.exe位置,如
command[0] = "C:\\Program Files (x86)\\Java\\jdk1.7.0_25\\bin\\java.exe"但
1)如果最终用户已经在其他地方安装了java,该怎么办?
2)如果路径环境变量包含64位JVM位置,那么如果我只给出java.exe
我尝试了下面的代码,但无法使用此方法传递参数。
String command = {"rundll32 url.dll,FileProtocolHandler ", jarFile + "" , arg1, arg2}
Process p = Runtime
.getRuntime()
.exec(command);那么,还有其他方法通过向jar文件传递参数来启动jar文件吗?
发布于 2013-07-26 11:23:27
使用参数' -d32 ',即java -d32 -jar jarfile arg1 arg2。
java -help也很方便。
https://stackoverflow.com/questions/17879348
复制相似问题