开发者

How to make Java program installable?

How can I 开发者_如何学Pythonmake a java program installable?

I have an application saved in my Eclipse workspace.

I can export it as a .jar file.

This is for a "real-world" application.

How can I export to be a ".exe" file or ".dmg" so that it can be installed on another machine?

Since Java is platform-independent I think it is a matter of exporting for a specific operating system.

I've googled a lot and read so many different stories, so I would prefer an answer from an experienced person.


I guess what you are looking for is not only to make the program runnable (as lobster1234 proposed) but to make it actually installable. We have recently used IzPack. It actually looks nice.

There are also some decent tutorials on the details here and here


Jar files are usually the way to go, since the JVM can directly execute the packaged files through the java -jar <jarfile> command. Java WebStart is good if you want to distribute your app from a web site, etc. However, some OS don't have that "feature" installed, even if the JVM is there. Another solution is to have at least 3 scripts to launch your app (batch for Windows, shell script for Linux, and whatever Mac needs -- sorry, don't have a Mac -- ).

Don't create native executable files (i.e. exe for Windows), they are redundant since you already have a JVM for that.


I'm risking a flamewar here but I'm game :) Unless you're on a platform where the JRE is already known to exist (ex. OS X) it's going to be a hassle for you and/or end users. The problem is java apps are simply not standalone and depend on a massive framework.

The JRE, Java Web Start, or whatever you use has to be put on the target system. Also you have to have a launcher of some sort. It could be something as simple as a script which runs java, supplies the classpath, etc. This wouldn't be needed if java "compiled" to an .exe or something but that's just how it works.

This is one of the reasons I've turned off on deploying Java to end-user machines. It's just a lot of trouble. I once worked on a project where we actually embedded an entire private jre that got deployed by the installer. It wasn't pretty but it got the job done.


As of Java 8, jdk is now capable of generating it's own Installables for Windows, OSX, and Linux. However, on Windows it depends on either Inno Setup 5 or later or WiX 3.0 or later.

https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html#A1324980

The easiest way to produce a self-contained application is to modify the deployment task. <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" nativeBundles="all" outdir="${basedir}/${dist.dir}" outfile="${application.title}"> <fx:application name="${application.title}" mainClass="${javafx.main.class}"/> <fx:resources> <fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/> </fx:resources> <fx:info title="${application.title}" vendor="${application.vendor}"/> </fx:deploy>


Guys already gave you a lot of options so I do not want to mention them again. The only option that is missing here is a case when you really need to install your program, meaning execute some logic, modify (or at least read) system configuration, create desktop shortcuts, copy many files, configure third party products (that are probably already installed) etc.

In this case you can use InstallAnywere, EzPack or similar solutions (see http://java-source.net/open-source/installer-generators) For example if your project is relatively simple I'd recommend you AntInstaller.

BTW if you afraid that your customer probably does not have JRE installed on his machine you can package your code (or better a loader) using Launch4J that generates executable from your java code.


You can use Java WebStart, or package the program as an executable jar file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜