Sign in to follow this  
LinkOfTime

[java] A question about Jar files...

Recommended Posts

LinkOfTime    128
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   
Guest Anonymous Poster
This might help:

http://csdl.ics.hawaii.edu/~johnson/613f99/modules/04/jar-files.html

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
pinacolada    834
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:

Quote:

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
rg/batik/)
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this