简体   繁体   English

制作独立的Java EXE文件

[英]Making a Stand-Alone Java EXE File

I'm currently a student at a high school, and I found a game programming competition for a club called FBLA. 我现在是一名高中生,我找到了一个名为FBLA的俱乐部的游戏编程竞赛。 I had a few questions about the competition, and so I emailed them. 我对比赛有几个问题,所以我给他们发了电子邮件。

I made a post earlier on Computer Science Stack Exchange, where you can view here . 我之前在Computer Science Stack Exchange上发了一篇文章,你可以在这里查看。

Now after receiving feedback from the question, someone commented that I should post my next question on this website. 现在收到问题的反馈后,有人评论说我应该在这个网站上发布我的下一个问题。


My question is that how would I be able to package a Java JAR file with the native libraries, and then create an EXE out of it, so it will be a stand alone? 我的问题是,我如何能够将Java JAR文件与本机库打包在一起,然后从中创建一个EXE,那么它将是一个独立的?

In my theory, I would have to create the jar, and put the required native files when a person installs java on their machine, into that JAR file, and then I can use a program such as FatJar or JSmooth. 在我的理论中,我必须创建jar,并在一个人在他们的机器上安装java时将所需的本机文件放入该JAR文件中,然后我可以使用诸如FatJar或JSmooth之类的程序。

If I'm wrong, or how I could understand a bit more on how jars are ran, it would help considerably. 如果我错了,或者我怎么能更多地了解罐子的运行方式,那将会有很大帮助。


Update Nov. 8, 2014 2014年11月8日更新
I finally got back around to messing with it, and I downloaded Launch4j. 我终于回过头来搞乱它了,我下载了Launch4j。 I set up and did everything with it, and I make an executable, which contains all of java's core native files. 我设置并使用它完成所有操作,并创建一个可执行文件,其中包含所有java的核心本机文件。 I uninstalled all of my programs dealing with java, and when I went to run it, it still required java. 我卸载了所有处理java的程序,当我去运行它时,它仍然需要java。

Once again to state what I need to happen: 再一次陈述我需要发生的事情:
What needs to happen is the executable will be able to run even if there's not any version of Java installed on the judge's computer. 即使在法官的计算机上没有安装任何版本的Java,可执行文件也能够运行。

I would reccomend you use launch4j. 我建议你使用launch4j。 http://launch4j.sourceforge.net http://launch4j.sourceforge.net

I've used it for some larger projects and it worked very well. 我已将它用于一些较大的项目,并且效果非常好。

It can encapsulate your jar, dependencies and even a JRE into a windows in executable. 它可以将jar,依赖项甚至JRE封装到可执行文件的窗口中。 It has a GUI or you can run from the command line. 它有一个GUI或您可以从命令行运行。

Checkout Packr,由libGDX团队创建: https//github.com/libgdx/packr

To make your jar executable, you specify the main class of your application, any extra jar files it may require and so on in the jar's manifest file: 要使jar可执行,您可以在jar的清单文件中指定应用程序的主类,它可能需要的任何额外jar文件等等:

Main-Class: MyAppMain
Class-Path: MyLib.jar

Then you use the jar utility from the Java SDK to package your classes and resource files, specifying the m option and the name of your manifest file: 然后使用Java SDK中的jar实用程序打包类和资源文件,指定m选项和清单文件的名称:

jar cvfm MyApp.jar MyApp.mf *.class *.gif

This will result in the creation of MyApp.jar . 这将导致MyApp.jar的创建。 Now, if you type 现在,如果你输入

java -jar MyApp.jar

the Java launcher will read the manifest from MyApp.jar , place that file and MyLib.jar on classpath and invoke the main method from the class MyAppMain . Java启动程序会读取清单MyApp.jar ,该文件放置 MyLib.jar类路径和调用从类的主要方法MyAppMain

Now, if your Java app needs native libraries, you also need to specify the java.library.path property pointing to the directory(ies) holding those: 现在,如果您的Java应用程序需要本机库,您还需要指定指向包含这些目录的目录的java.library.path属性:

java -Djava.library.path=.\bin -jar MyApp.jar

For more info and alternative solutions, refer to my article . 有关更多信息和替代解决方案,请参阅我的文章

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

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