我有一个Java应用程序,我即将开始使用Web Start进行部署。但是一个新的需求让我重新思考这一点,因为我现在需要添加一些功能,允许最终用户选择他们是否想在启动时运行该程序(Windows,而不是跨平台) )。但是我仍然希望避免将这种运行作为一种服务。有没有办法可以使用Web Start完成,或者我应该探索其他选项来部署它?提前谢谢。
答案 0 :(得分:4)
它实际上可以将它放在jnlp文件中:
<shortcut online="true">
<desktop/>
<menu submenu="Startup"/>
</shortcut>
但这仍然适用于英文版Windows。德语是“自动启动”,我认为西班牙语是“Iniciar”。因此它与通过IntegrationService的方式引起了同样的麻烦。
答案 1 :(得分:1)
我还没有尝试过,但我想知道你是否可以将新的JNLP IntegrationService与javaws命令行程序结合使用。想法是以编程方式在Windows启动组中创建快捷方式(尽管该位置依赖于特定的Windows版本)。
答案 2 :(得分:1)
要解决Startup文件夹的语言问题,只需使用注册表即可。这是一些应该有效的代码。这会调用reg.exe进行注册表更改。
public class StartupCreator {
public static void setupStartupOnWindows(String jnlpUrl, String applicationName) throws Exception {
String foundJavaWsPath = findJavaWsOnWindows();
String cmd = foundJavaWsPath + " -Xnosplash \"" + jnlpUrl + "\"";
setRegKey("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", applicationName, cmd);
}
public static String findJavaWsOnWindows() {
// The paths where it will look for java
String[] paths = {
// first use the JRE that was used to launch this app, it will probably not reach the below paths
System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaws.exe",
// it must check for the 64 bit path first because inside a 32-bit process system32 is actually syswow64
// 64 bit machine with 32 bit JRE
System.getenv("SYSTEMROOT") + File.separator + "syswow64" + File.separator + "javaws.exe",
// 32 bit machine with 32 bit JRE or 64 bit machine with 64 bit JRE
System.getenv("SYSTEMROOT") + File.separator + "system32" + File.separator + "javaws.exe",};
return findJavaWsInPaths(paths);
}
public static String findJavaWsInPaths(String[] paths) throws RuntimeException {
String foundJavaWsPath = null;
for (String p : paths) {
File f = new File(p);
if (f.exists()) {
foundJavaWsPath = p;
break;
}
}
if (foundJavaWsPath == null) {
throw new RuntimeException("Could not find path for javaws executable");
}
return foundJavaWsPath;
}
public static String setRegKey(String location, String regKey, String regValue) throws Exception {
String regCommand = "add \"" + location + "\" /v \"" + regKey + "\" /f /d \"" + regValue + "\"";
return doReg(regCommand);
}
public static String doReg(String regCommand) throws Exception {
final String REG_UTIL = "reg";
final String regUtilCmd = REG_UTIL + " " + regCommand;
return runProcess(regUtilCmd);
}
public static String runProcess(final String regUtilCmd) throws Exception {
StringWriter sw = new StringWriter();
Process process = Runtime.getRuntime().exec(regUtilCmd);
InputStream is = process.getInputStream();
int c = 0;
while ((c = is.read()) != -1) {
sw.write(c);
}
String result = sw.toString();
try {
process.waitFor();
} catch (Throwable ex) {
System.out.println(ex.getMessage());
}
if (process.exitValue() == -1) {
throw new Exception("REG QUERY command returned with exit code -1");
}
return result;
}
}