How do I make deployable '.jar' files that run on a double-click as a JBuilder 4 Foundation user?

Dave Arroyo

When you install the the Java Runtime Environment, one of the things you get is a new file association on the file extension '.jar'. In the file types list it will show as 'Executable Jar File'. It associates the .jar file extension with the invocation of javaw.exe -jar. With the right kind of jar you can have a Java application run on a double click. You can verify the JRE is ready to roll by double-cling on another example of a executable jar in the JDK installed by JBuilder 4 such as Notepad.jar.

So what is the right kind of jar? It is the kind that describes a main-class in its manifest, but there is more to it if your main class has a package statement. Take the WelcomeApp example in the JBuilder 4 samples directory.

In it's source it says it is part of package com.borland.samples.welcome.WelcomeApp. If you were to read the information at Sun's JAR tutorial which is mentioned in your JBuilder 4 manual, you will learn some things about putting together jar files, but not what I'm about to show you. You should still read it because as a Foundation owner, you are going to be your own archive builder.

To make a good WelcomeApp.jar:

First, create your own copy of Manifest.mf. Derive from the package statement com.borland.samples.welcome.WelcomeApp the classpath, which in this case is 'com/borland/samples/welcome/'. It's essentially taking the 'dots' out of the package statement and lopping off the class name of the main-class. The manifest file contents should look like:

Manifest-Version: 1.0
Main-Class: com/borland/samples/welcome/WelcomeApp
Created-By: 1.3.0 (Sun Microsystems Inc.)


If you did 'Main-Class: WelcomeApp' you are on your way to getting a 'main class not found error' that will thwart you running WelcomeApp.jar on a double-click.

Second, make yourself a text file and rename it to MakeJar.bat or whatever you want to call it, but make it a batch file. Throw this into the file:

jar cmf Manifest.mf WelcomeApp.jar com/borland/samples/welcome/WelcomeFrame$1.class com/borland/samples/welcome/WelcomeFrame$2.class com/borland/samples/welcome/WelcomeFrame.class com/borland/samples/welcome/WelcomeApp.class

Notice how the classpath is used. This is part of liberating you or anyone else from having to deal with classpaths once this jar is made.

Third, take your Manifest.mf and your MakeJar.bat and put them in the directory the contains the 'com/borland/samples/welcome/' path. In the case of the WelcomeApp sample, it's 'JBuilder4/samples/Welcome/classes/'. It is vital to run the batch file from here, and have your manifest file here.

Fourth, run the batch file MakeJar.bat. By the way, you should be able to actually run the jar.exe anywhere on your machine by having the path statement to '[your machine's path to JBuilder4]/JBuilder4/jdk1.3/bin' in your autoexec.bat.

If everything goes as planned, you should be able to double-click on the new WelcomeApp.jar and it will run.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact