File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes define the main class in a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "define the main class in a jar " Watch "define the main class in a jar " New topic

define the main class in a jar

chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 197

I created a swing application.
I want to create a jar (I know how to do that) that will activate the application meaning, if the user will push on X.jar the application will start running.

How can I define the main class?

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Like with all applications, you need a class with a main method to start the application. Then you need to add a manifest file to the jar which references the class with the main method; see JarFiles for more details.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

You have to create a manifest file and include the following line:

Then, when creating the JAR file, specify that you want to include a manifest file, and use the one you just created/

How To Ask Questions How To Answer Questions
chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 197

I add all the necessaries directories (also properties and .classpath) to the jar.
When I am trying to run the jar I get the fallowing error:

Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name rcyProperties, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at utils.RcyUtils.getResourceBundle(
at utils.RcyUtils.getImageIcon(
at gui.BootScreen.<init>(
at main.StartRcy.main(

The properties directory is define in the .classpath file.
Should I need to add this directory also into the manifest.txt (and how)?

I agree. Here's the link:
subject: define the main class in a jar
It's not a secret anymore!