Jump to content
  • Advertisement
Sign in to follow this  

[java] A question about Jar files...

This topic is 4786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all I was trying to create a jar file today from a few .class files and it worked. But then, when I tried running the Jar file, it gave me an error and then I thought, how do I tell the Jar file which class to run when I open it? (I am new to the Jar files subject :) ) Thanks for the help everyone :)

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
This might help:


If not, elaborate- what was the error, for instance? Did you set the main class?

Hope that helps =)

Share this post

Link to post
Share on other sites
Java will look inside the .jar for a file called MANIFEST.MF, in a folder called META-INF. Here's what a sample manifest file looks like:


Manifest-Version: 1.0
Main-Class: org.apache.batik.apps.svgbrowser.Main
Created-By: Ant 1.4.1
Implementation-Vendor: Apache Software Foundation (http://xml.apache.o
Class-Path: lib/batik-ext.jar \ lib/batik-dom.jar \
lib/batik-css.jar \ lib/batik-svg-dom.jar \ lib
/batik-gvt.jar \ lib/batik-parser.jar \ lib/batik
-script.jar \ lib/batik-bridge.jar \ lib/batik-sw
ing.jar \ lib/batik-transcoder.jar \ lib/batik-gu
i-util.jar \ lib/batik-awt-util.jar \ lib/batik-u
til.jar \ lib/batik-xml.jar \ lib/xerces_2_5_0.ja
r \ lib/xml-apis.jar \ lib/js.jar
Implementation-Version: 1.6
Implementation-Title: Batik Squiggle Viewer

So it's right there: the "main-class" attribute is what tells it which class to run.

Usually, whatever tool/IDE you use to make the .jar file will take care of creating this file for you. So the task of changing the "main-class" depends on the tool you're using to make the jar.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!