我有一個即將開始使用Web Start部署的Java應用程序。但是新的需求使我重新思考了這一點,因爲我現在需要添加一項功能,允許最終用戶選擇是否希望在啓動時運行此程序(Windows,而不是跨平臺)。但是我仍然希望避免將此作爲服務。有什麼方法可以使用Web Start來完成,或者我應該探索其他選項來部署它嗎?提前致謝。在Windows啓動時部署Java Web Start
回答
我還沒有嘗試過,但是我想知道是否可以將新的JNLP IntegrationService與javaws命令行程序結合使用。這個想法是以編程方式在Windows啓動組中創建一個快捷方式(儘管該位置取決於特定的Windows版本)。
它的實際工作,以把這個在JNLP文件:
<shortcut online="true">
<desktop/>
<menu submenu="Startup"/>
</shortcut>
但仍然只能用英文版的Windows版本。德語是「Autostart」,西班牙語是我認爲的「Iniciar」。所以它通過IntegrationService的方式導致基本相同的頭痛。
要解決啓動文件夾的語言問題,只需使用註冊表。這是一些應該可以工作的代碼。這會調用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;
}
}
This Works!也許有點慢(應用程序幾秒鐘沒有響應,我想這可能是因爲這個代碼),但工作。現在我需要將自己的應用程序本身放在自動啓動中(不通過JNLP文件)... – 2014-03-23 22:14:26
通過SwingWorker運行代碼,它將在後臺運行。 – 2014-03-24 17:02:59
是的,我在一個單獨的線程運行它!謝謝! – 2014-03-25 18:03:43
- 1. 啓動Java Web Start時檢查更新
- 2. Java Web Start啓動畫面不顯示
- 3. 無法啓動Java Web Start的
- 4. Java Web Start不啓動問題
- 5. java web start無法在第二次運行時啓動
- 6. 從Web Start啓動Runnable Jar
- 7. Java Web Start部署中的應用程序邏輯在哪裏?
- 8. 通過Java Web Start(JNLP)啓動的Applets啓動兩次
- 9. 使用Java Web Start啓動JavaFX 2.2應用程序時出錯
- 10. Java Web Start驅動安裝
- 11. 如何在系統啓動時自動啓動部署在Apache Tomcat上的java
- 12. web部署後自動啓動網站
- 13. 部署Windows Web App?
- 14. 在tomcat部署時自動啓動web應用程序
- 15. 在Windows上運行mongrel_rails cluster :: start啓動
- 16. 使用Java Web Start(JNLP)部署* .war應用程序
- 17. 部署Java Web Start的數據庫遷移應用程序
- 18. java web start JAVA_HOME
- 19. Java Web Start getDocumentBase
- 20. java web start alternative
- 21. java web start launch
- 22. 在受保護的站點上無法啓動Java Web Start
- 23. java web start應用程序無法在java7u45上啓動
- 24. 在Java Web Start中啓動文件錯誤
- 25. Azure通過自動部署啓用Web部署
- 26. 有關Java Web Start
- 27. Java Web Start的 - 在JNLP
- 28. 指紋在Java Web Start的
- 29. ClickOnce部署 - 在啓動時運行
- 30. 使用Java Web Start
嗯......有趣的想法。謝謝,我會努力的。 – Glockstock 2010-10-26 19:50:21
有人試過這種方法嗎? – 2014-03-15 20:31:13