简体   繁体   English

运行Java应用程序双击

[英]Run Java applications By double click

why i can`t run my java compiled applications with double click? 为什么我不能用双击运行我的java编译应用程序? my applicatins just run in cmd (java -jar: my app.jar) plz help me 我的应用程序只是在cmd中运行(java -jar:我的app.jar)plz帮助我

You can make a batch file to run your command. 您可以创建批处理文件来运行命令。 This way it will work without the need to make associations to .jar files. 这样它就可以在不需要与.jar文件建立关联的情况下工作。 If it is a windows app then start it with javaw.exe. 如果它是一个Windows应用程序,然后用javaw.exe启动它。

You need to associate the .jar extension with javaw.exe , then no console window will be shown, when you double click the jar file 您需要将.jar扩展名与javaw.exe关联,然后双击jar文件时不会显示任何控制台窗口

This is usually done by the JDK/JRE installer, so either you didn't install the JDK properly, or you manually changed that associaten. 这通常由JDK / JRE安装程序完成,因此要么您没有正确安装JDK,要么手动更改了该关联。

I think all the answer here are valid. 我认为这里的所有答案都是有效的。 But if you want a true executable file in Windows then you need to create a launcher. 但是如果你想在Windows中使用真正的可执行文件,那么你需要创建一个启动器。 In windows, jar files are not executable. 在Windows中,jar文件不可执行。 But exe files are. 但exe文件是。 There are many tools out there than wrap all your java code around some native library. 有很多工具,而不是围绕一些本地库包装所有的java代码。 I recommend http://launch4j.sourceforge.net/ I think this is what you are looking for. 我推荐http://launch4j.sourceforge.net/我认为这就是你要找的东西。 You can easily create executable with icons and many more features. 您可以使用图标和更多功能轻松创建可执行文件。

You can create a Windows shortcut to your .jar file. 您可以创建.jar文件的Windows快捷方式。

The following line could be the target of the Windows shortcut. 以下行可以是Windows快捷方式的目标。

%windir%\system32\javaw.exe -Xms1m -Xmx1m -jar "C:\Program Files\Jar Directory\file.jar"

This has the advantage of allowing you to specify the javaw parameters that you want, as well as the Windows parameters (normal window, maximized, start in directory) that you want. 这样做的好处是允许您指定所需的javaw参数,以及所需的Windows参数(普通窗口,最大化,在目录中启动)。

Just assign .jar files to be executed by javaw.exe . 只需分配要由javaw.exe执行的.jar文件。 You can do that using the Open with dialog on a .jar file. 您可以使用.jar文件上的“ Open with对话框执行此操作。

BTW, doesn't the Java installer do that for you? 顺便说一句,Java安装程序不是为你做的吗?

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

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