By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,469 Members | 1,885 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,469 IT Pros & Developers. It's quick & easy.

jar archive

P: n/a
Hello.
I wrote a program that I want to put in a executable jar archive. How do I
do that? Program has 2 classes in a package. I tried something like
"jar -cfv program.jar class1.class class2.class" but it I got error that
main class cannot be found. How can I specify the main class? Tnx.

--
Kova
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Kova wrote:
Hello.
I wrote a program that I want to put in a executable jar archive. How do I
do that? Program has 2 classes in a package. I tried something like
"jar -cfv program.jar class1.class class2.class" but it I got error that
main class cannot be found. How can I specify the main class? Tnx.


Kova,

It sounds like you left out a few steps in the above description. I
assume you got the main class error when you tried to run the jar file.

To specify the main class, you use a manifest file. The manifest
contains an entry Main-Class whose value is the class you wish to invoke
when the jar is run. A simple manifest for the class com.xyz.Main would
look like:

Main-Class: com.xyz.Main
(NB: Put an empty line at the end of your manifest file. I've seen the
jar program skip the last entry if the blank line is missing!)

To create the jar with the manifest, use the m option:

jar cvfm program.jar my-manifest.mf com/xyz/Main.class

Note that the manifest file is placed in the jar under the enter
META-INF/MANIFEST.MF (although capitalization will differ depending on
the version of jar; UNIX guys love that feature).

If this doesn't help, please post more explicit instructions. Or you
could search the archives on Google, I've helped with this issue before
and please have posted very explicit stuff on what they did.

Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2

P: n/a
> To specify the main class, you use a manifest file. The manifest
contains an entry Main-Class whose value is the class you wish to invoke
when the jar is run. A simple manifest for the class com.xyz.Main would
look like:

Main-Class: com.xyz.Main


Thanks, I got it working! I didn't know that for packages you need
indentical directory structure in manifest.

--
Kova
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.