Creating Jar File

I have created an eclipse project.  I can run it through Eclipse but am having trouble running it via command prompt:

                                             lp
                       bin                                    source
   example                                                              example
*.class                                                                             *.java

How can I create a jar file as well.  The entry point is located in Main.class.  Where and what should go in the manifest?
abstractionzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>what should go in the manifest?

The following:

Main-Class: Main
0
abstractionzAuthor Commented:
ok, but why doesnt

java example.Main  work in the command prompt.  get NoClassDefException when run from the directory lp

also, where does the manifest go and how can I create the jar
0
objectsCommented:
java -classpath /lp/bin/example Main

(assuming you don't use a package).
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

objectsCommented:
if its in example package then use:

java -classpath /lp/bin example.Main

0
CEHJCommented:
If you're using packages:

Main-Class: Main
Class-Path: lp/bin
0
objectsCommented:
jar cvf my.jar example
0
CEHJCommented:
Sorry:

Main-Class: example.Main
Class-Path: lp/bin

Then run

java -jar YourJar
0
objectsCommented:
the jar file will get created automatically.

if you want to make it an executable jar then create a manifest file with the following line:

Main-Class: example.Main
0
objectsCommented:
0
abstractionzAuthor Commented:
im still getting the NoClassDefFoundError
0
abstractionzAuthor Commented:
its in example package
0
objectsCommented:
what command are you using?

should be:

java -classpath /lp/bin example.Main

0
objectsCommented:
> java example.Main  work in the command prompt.  get NoClassDefException when run from the directory lp

because if you have no classpath set it automatically adds the current directory.
0
abstractionzAuthor Commented:
yea, that's not working
0
CEHJCommented:
Since you're using a manifest, if you write it properly (see my last manifest), you don't need anything other than

java -jar YourJar
0
CEHJCommented:
(with the extension .jar)
0
objectsCommented:
what os?
0
objectsCommented:
try:

java -classpath \lp\bin example.Main
0
abstractionzAuthor Commented:
that didn't work either.  i'm running windows xp pro 1a.  project is located @  f:\code\lp
0
CEHJCommented:
If you're not using a manifest, you command should be

java -classpath YourJar.jar example.Main
0
abstractionzAuthor Commented:
it runs fine via Eclipse
0
CEHJCommented:
... but that  wouldn't work if you've not got a corresponding package structure
0
objectsCommented:
java -classpath f:\code\lp\bin example.Main
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
objectsCommented:
and if you want a jar, see the command I posted earlier to create it :)
0
abstractionzAuthor Commented:
thank you that worked
0
objectsCommented:
good stuff :)
0
CEHJCommented:
I'm getting confused now - the point of this is to use a jar is it not abstractionz ?
0
CEHJCommented:
What did that have to do with a jar?
0
objectsCommented:
question stated "I can run it through Eclipse but am having trouble running it via command prompt:"
and i also posted how to build jar anyways,
0
abstractionzAuthor Commented:
i tried running

jar cmf \bin\mymanifest lp.jar \bin\example

but when i run lp.jar i get a NoClassDefFoundError
0
abstractionzAuthor Commented:
in the manifest was

Main-Class: example.Main
0
objectsCommented:
try:

jar cmf f:\code\lp\bin\mymanifest lp.jar f:\code\lp\bin\example

0
abstractionzAuthor Commented:
get the same error
0
objectsCommented:
post the contents of your jar using:

jar tvf lp.jar
0
abstractionzAuthor Commented:
F:\code\lp>jar tvf lp.jar
     0 Thu Nov 25 20:47:38 EST 2004 META-INF/
    97 Thu Nov 25 20:47:38 EST 2004 META-INF/MANIFEST.MF
     0 Wed Nov 17 22:41:58 EST 2004 f:/code/lp/bin/example/
  1777 Wed Nov 17 22:23:42 EST 2004 f:/code/lp/bin/example/Atom.class
  2257 Wed Nov 17 22:23:42 EST 2004 f:/code/lp/bin/example/Clause.class
   897 Wed Nov 17 22:23:42 EST 2004 f:/code/lp/bin/example/Constant.class
  2127 Wed Nov 17 22:23:40 EST 2004 f:/code/lp/bin/example/Function.class
   654 Thu Nov 18 15:36:14 EST 2004 f:/code/lp/bin/example/Main$BookOfTheDay.cla
ss
  1340 Thu Nov 18 15:36:14 EST 2004 f:/code/lp/bin/example/Main.class
  1566 Wed Nov 17 22:23:40 EST 2004 f:/code/lp/bin/example/Predicate.class
  1363 Wed Nov 17 22:23:40 EST 2004 f:/code/lp/bin/example/Substitution$Element.
class
  2257 Wed Nov 17 22:23:40 EST 2004 f:/code/lp/bin/example/Substitution.class
   555 Wed Nov 17 22:23:40 EST 2004 f:/code/lp/bin/example/Term.class
  4847 Wed Nov 17 22:23:40 EST 2004 f:/code/lp/bin/example/TheoremProver.class
  1042 Wed Nov 17 22:23:40 EST 2004 f:/code/lp/bin/example/Variable.class
  6371 Thu Nov 18 03:25:36 EST 2004 f:/code/lp/bin/example/XMLProgram.class
0
objectsCommented:
cd to f:/code/lp/bin and try

jar cmf mymanifest lp.jar example
0
abstractionzAuthor Commented:
that worked.  thanks again.
0
objectsCommented:
no worries :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.