How to create Java executable programs and installation programs (with the picture added)

Source: Internet
Author: User

First, we will introduce three methods for generating and running Java programs -----
Java-generated jar packages are generally executed in three ways:
1. Run j2se Binnary directly. The jar package can also be opened with WinRAR, causing a conflict. You can set the file association. In this case, the jar package and the. exe file are no different. In addition, the platform type is not lost.
2. write scripts. It is. BAT in windows and. Sh in Linux or UNIX. In fact, I personally think This is simpler. In addition, many large programs work in this way. For example, Tomcat and WebLogic are both started using this script. The advantage is that you can set various system environment variables, check the running environment, and change the startup parameters. For example, in windows, we only need to add "Start Java-jar XXX. Jar.
3. Use various third-party tools to create a. bin(unix(, cmd.exe (Windows) file. However, this is conditional on the loss of cross-platform features. Of course, the benefit is a better user experience.
First, you can install j2se.
Second, we can give an example.
Suppose there is a allwefantasy. jar jar package (which contains the manifest file), so in the same directory, I create a allwefantasy. BAT (the name can be set at will. If it is on a Linux platform, change it to the sh suffix ). Content is
Start Java-jar XXX. Jar
. Double-click to run the task.
The third is the focus of my article.
Pack the jar package into an EXE Executable File
In fact, this method is applied in JDK. I don't know if you have noticed that % java_home %/binshould contain all the. exe files, but take a closer look at these files with only a few Kb. Why? This is because it is just a wrapper. the package is still running the JAR file. It can also be called a pseudo-EXE file. Then, how can we make the JAR file into an EXE file that can be directly run? Here I will introduce the two I used. Nativej and open-source jsmooth.
I personally prefer to use open-source products. I 'd like to introduce jsmooth first.

It is easy to use. In the first drop-down box on the skeleton tab, windowsed wrapper.

Next, select the executable tab. the first blank is the name of the EXE file you want to generate. If you want to create an icon for your EXE file, you can create an ico image file and then use it.
The third empty is the directory where your jar package is located.

In the application, select the full path of your main-class from the first empty post on the graphics card. I don't know if it is clear, that is, the package name + main function name in the directory where your main function is located. For example, drawsmart. itsv. appmain is in the example I want to talk about.
Then select use an embedded. jar.
Finally, select the jar package you need.
Click the compile button. Project-compile-

Next we will introduce nativej. As the name suggests, nativej is the meaning of localized Java.
This software needs to be purchased. Otherwise, a box containing the generated exe will pop up during startup. When the file is executed, it will pop up and declare that this program is generated by it ..
Without much complaints, it is not easy for people who do software.

When I started to use it, I felt inexplicable and had no way to do it. Later I thought about it before I understood it. Create a directory in advance and create an empty suffix named njp text file in the directory.
Click New Project Wizard,
Select the project file you just created. Then, enter some parameters in sequence. The parameters are similar to those of jsmooth, including the full path of the main class (package name + class name) and jar package.
Finally, we can generate the expected EXE file.
This

Is the file I generated.
Note that the EXE files generated by jsmooth and nativej are still different. I don't know if the settings will change.
As shown in nativej, because Jar does not include all files into the package, for example, images., the generated EXE file is still from the jar package and other files. I personally feel a bit like a bat file.
In jsmooth, an EXE file is generated, but the file is large. It seems to contain the entire jar package and resource file, but it cannot be executed independently (why, I didn't understand ).

How to create an installer for a Java program
Creating an installer is not a simple task. Especially for large programs. It takes you half an hour to install oracle. There are a lot of installation and production programs, large commercial classes include intallanywhere and InstallShield. The functions are super powerful, but after all, they are commercial software and need to be paid for money. In addition, the learning curve is steep due to strong functions.
Here I will introduce an open source software. Izpack. You can go to the official website.
During installation, you can see the installation interface that he made on his own.

After installation, you must find its own directory. There are two points that you may not get used to. First, you do not have a graphical interface. Second, you cannot run the install. xml file you need.
Maybe you don't quite understand. It doesn't matter. Let's talk about his design philosophy.
The installer has only a few interface sections, and the language selection. The first figure above shows the license statement, such as the second figure, the installation process, and the installation end interface. In izpack, these are called panels. Izpack uses the install. xml file to configure these panels. Of course, he still has a lot of internal details, such as registry registration. Of course, this is another thing. Then generate a jar package (which is a jar package again. Why don't I generate the EXE file directly? I don't know this. You have to ask the designer: in fact, it is still for cross-platform ).
So how do I write the install and XML documents? There are more than one hundred and fifty businesses in the manual, so let's take a look. However, I can take a self-developed example.
<? XML version = "1.0" encoding = "UTF-8" standalone = "yes"?>
<Installation version = "1.0">
// Info mainly refers to the version author information.

<Info>
<Appname> my image book </appname>
<Appversion> 1.4 beta </appversion>
<Authors>
<Author name = "Guansheng" email = "wgs@superman.org"/>
<Author name = "haillin" email = "zhl@hisdomain.com"/>

</Authors>
<URL> http://www.superman.net/</URL>
</INFO>

// Guiprefs mainly sets the size of the installation interface and whether the size can be changed.
<Guiprefs width = "640" Height = "480" resizable = "no"/>

// It is very similar to the internationalization in Java. I have never counted it, But izpack supports languages in many countries. I chose English and Chinese. Note that the abbreviation of the language is different from that in Java. For more information, see
<Locale>
<Langpack iso3 = "eng"/>
<Langpack iso3 = "CHN"/>
</Locale>

// The resource file loves you. I have posted the license statement and read the README file.

<Resources>
<Res id = "licencepanel. Licence" src = "licence.txt"/>
<Res id = "infopanel.info" src = "readme.txt"/>
</Resources>

// This is the beginning, installation, and Declaration sections of each section.
<Panels>
<Panel classname = "hellopanel"/>
<Panel classname = "infopanel"/>
<Panel classname = "licencepanel"/>
<Panel classname = "targetpanel"/>
<Panel classname = "packspanel"/>
<Panel classname = "installpanel"/>
<Panel classname = "finishpanel"/>
</Panels>

<Packs>
<Pack name = "base" required = "yes">
<Description> the base files </description>
<File src = "readme.txt" targetdir = "$ install_path"/>
<File src = "licence.txt" targetdir = "$ install_path"/>
<File src = "kitty.exe" targetdir = "$ install_path"/>
<Parsable targetfile = "$ install_path/kitty.exe"/>
// Copy the file to the installation folder.
</Pack>
<Pack name = "image" required = "yes">
<Description> the documentation </description>
<File src = "Images" targetdir = "$ install_path"/>

</Pack>
<Pack name = "xmlfile" required = "yes">
<Description> the sources </description>
<File src = "xmlfile" targetdir = "$ install_path"/>
</Pack>
<Pack name = "Temp" required = "yes">
<Description> the sources </description>
<File src = "Temp" targetdir = "$ install_path"/>
</Pack>
<Pack name = "drawflow" required = "yes">
<Description> the sources </description>
<File src = "drawflow3_0.jar" targetdir = "$ install_path"/>
</Pack>

<Pack name = "service" required = "yes">
<Description> the sources </description>
<File src = "service. ICO" targetdir = "$ install_path"/>
</Pack>
<Pack name = "addon" required = "yes">
<Description> the sources </description>
<File src = "add-on" targetdir = "$ install_path"/>
</Pack>
</Packs>

</Installation>

After writing this file, place it in the main directory where you want to make the installation file, and then use compile. run BAT to get a jar file, I am stuck here for a lot of time)
How can I generate a jar file?
Last step

Convert the jar package installer into an EXE Installer
In fact, this step is to use jsmooth to make the jar installer wrapper into an EXE. This is the final result.
Therefore, three steps are used. Jar program -- jsmooth --- exe program ---- izpack --- jar installer --- jsmooth-EXE installer.
If you want to be more professional, you can use installsheild or intallanywhere. The two software, graphical interface, and operability are quite good. For learning, he does not need a registration code. The only drawback is that if you do not register the product, the prompt box indicating that the product is not registered will pop up when you install the installation program.

I also saw a lot of online users asking questions on one hand, but they often did not get a good answer. So here is a summary. I hope to have more exchanges with you. If you have any questions, contact me:William@websiteempire.cn

 

----------------------

Welcome to the launch of the new website Website Transaction CenterYou can purchase or sell your website here.
Website information publishing centerVarious transaction information is released here. At the same time
Free use of some software (with source code ).
Website Blog systemYou can register your own blog here. An unlimited number of blogs under one account
Contact info: Support@websiteempire.cn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.