• Advertisement
Sign in to follow this  

[java] A question about Jar files...

This topic is 4525 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
Advertisement
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
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
Thanks, that's what I meant.
I will try what you said and if I encounter a problem, I will post it here.
Thanks again :)

Share this post


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

  • Advertisement