Creating exe files for Java Apps using Launch4j


 

 

I ran across the Launch4j project  while create a swing desktop application. I had used Netbeans to develop the app, but there were some configuration files outside of the app then needed to included in the classpath for it to work.

One option was to use a Windows batch file to launch the script. This didn’t seem to be the most elegant solution, so I did some research, and found Launch4j.

To get started, download the Launch4j at http://launch4j.sourceforge.net/

I just downloaded the zip file and extracted it under c:\program file.

When you run it, you’ll be greeted with this screen.l4j

It may look a bit overwhelming, but it’s really pretty simple.

The first thing I like to do is select my jar file for my project.

l4j2.png

From there, copy and paste the text in Jar to the Output file section, but change the extension to .exe

l4j3.png

I usually include an icon as well.

l4j4.png

The next step is to include classpath. Make sure the Custom classpath checkbox is selected, the browse for the jar file for you app under main class.

l4j_6.png

Notice that in the classpath section there is a jar file for the Apache commons project.  The simple app I’m using for this demo includes this jar, so it’s automatically include in the classpath.

You can also add other items to the classpath, such as configuration directory, by typing it into the Edit item portion and choosing accept.

 

 

l4j_7.png

You can also set the required Java version

l4j_8

That’s the basics,. although there are a bunch of other useful options as well.  At the point, click the save icon, and it will save your configuration as XML file.  Then click the gear icon, and it will generate your .exe file.f1.png

hwapp.png

 

Conditional Breakpoints in eclipse

Often in eclipse, it would useful to create a breakpoint that only will trigger on certain conditions.

In the past, a lot of developers would include code like this:

if1

This works, but adding temporary code for debugging is problematic. For example,  you would have to remember to remove it before moving to production.

Luckily, there’s a better way.  Eclipse allows conditional break points.

To use them, set a breakpoint as usual.

if2

Right click on the breakpoint, and use the context menu to go the properties.

cm

In the properties dialog, check the ‘Conditional’ check box.

cm3.png

Add your condition:

cm4

 

Click OK, and you’re done. Eclipse will now break on the condition, without having to add any temporary code to do so.

Make sure not to include a semi colon at the end, or you’ll get an error.