470,855 Members | 1,301 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

jar archive

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
2 4996
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
> 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.

Similar topics

reply views Thread by Евгений Косенко | last post: by
1 post views Thread by labrach | last post: by
1 post views Thread by DB2 Convert | last post: by
7 posts views Thread by William | last post: by
6 posts views Thread by JezB | last post: by
7 posts views Thread by Enigma Curry | last post: by
3 posts views Thread by Hallgeir Stuenes | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.