简体   繁体   English

Windows,双击运行 JAR

[英]Windows, run JAR with double click

I'm experimenting with Java for the first time.我是第一次尝试 Java。 I'm using Intellij IDEA and creating a simple app.我正在使用 Intellij IDEA 并创建一个简单的应用程序。 In the IDE it's working fine, then I create a JAR artifact and run it like this: java -jar myappname.jar with no problem.在 IDE 中它工作正常,然后我创建了一个 JAR 工件并像这样运行它:java -jar myappname.jar 没有问题。

Now I would like to start the same JAR with double-clicking it from explorer but nothing happens, why?现在我想通过从资源管理器中双击它来启动同一个 JAR,但没有任何反应,为什么?

Please note that if I double click another JAR (sikulixsetup-1.1.3.jar) it starts correctly and show the gui, so the problem is not type association in windows.请注意,如果我双击另一个 JAR (sikulixsetup-1.1.3.jar),它会正确启动并显示 gui,所以问题不在于 Windows 中的类型关联。

My test app does not have a gui but I know if it runs correctly because it's automating windows using Sikulixapi library, so I see if it's doing something or not.我的测试应用程序没有 gui,但我知道它是否运行正确,因为它使用 Sikulixapi 库自动执行窗口,所以我看看它是否在做某事。

thanks!谢谢!

Its because jar is not executable binary but plain zip archive.这是因为jar不是可执行的二进制文件,而是普通的 zip 存档。 OS cannot execute that.操作系统无法执行。 That is why you must use java executable and pass archive as argument to run your application.这就是为什么您必须使用java可执行文件并将存档作为参数传递来运行您的应用程序。

If you want your app to be "clickable" you must use some wrapper solution like http://launch4j.sourceforge.net/如果您希望您的应用程序“可点击”,您必须使用一些包装解决方案,例如http://launch4j.sourceforge.net/

Ok, I solved my issue.好的,我解决了我的问题。 Usually the JAR runs without any problem by simply double clicking it in windows, in my case it was not running becase the .jar files was associated to the 32bit version of javaw.exe while the code in the JAR was expecting the 64bit environment.通常,只需在 Windows 中双击 JAR 即可正常运行,在我的情况下,它没有运行,因为 .jar 文件与 32 位版本的 javaw.exe 相关联,而 JAR 中的代码需要 64 位环境。 Changing the .jar type association in windows from 32bit to 64bit version of javaw.exe solved the issue将 Windows 中的 .jar 类型关联从 32 位更改为 64 位版本的 javaw.exe 解决了该问题

更改在打开文件时使用的默认程序,从一种 Java 到另一种(32 位到 64 位,反之亦然)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM