?
Solved

Creating Jar File

Posted on 2004-11-25
38
Medium Priority
?
192 Views
Last Modified: 2010-03-31
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?
0
Comment
Question by:abstractionz
  • 17
  • 12
  • 9
38 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677786
>>what should go in the manifest?

The following:

Main-Class: Main
0
 

Author Comment

by:abstractionz
ID: 12677811
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
 
LVL 92

Expert Comment

by:objects
ID: 12677812
java -classpath /lp/bin/example Main

(assuming you don't use a package).
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 92

Expert Comment

by:objects
ID: 12677814
if its in example package then use:

java -classpath /lp/bin example.Main

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677819
If you're using packages:

Main-Class: Main
Class-Path: lp/bin
0
 
LVL 92

Expert Comment

by:objects
ID: 12677820
jar cvf my.jar example
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677825
Sorry:

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

Then run

java -jar YourJar
0
 
LVL 92

Expert Comment

by:objects
ID: 12677826
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
 
LVL 92

Expert Comment

by:objects
ID: 12677827
0
 

Author Comment

by:abstractionz
ID: 12677828
im still getting the NoClassDefFoundError
0
 

Author Comment

by:abstractionz
ID: 12677830
its in example package
0
 
LVL 92

Expert Comment

by:objects
ID: 12677841
what command are you using?

should be:

java -classpath /lp/bin example.Main

0
 
LVL 92

Expert Comment

by:objects
ID: 12677845
> 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
 

Author Comment

by:abstractionz
ID: 12677847
yea, that's not working
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677849
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677855
(with the extension .jar)
0
 
LVL 92

Expert Comment

by:objects
ID: 12677868
what os?
0
 
LVL 92

Expert Comment

by:objects
ID: 12677872
try:

java -classpath \lp\bin example.Main
0
 

Author Comment

by:abstractionz
ID: 12677880
that didn't work either.  i'm running windows xp pro 1a.  project is located @  f:\code\lp
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677882
If you're not using a manifest, you command should be

java -classpath YourJar.jar example.Main
0
 

Author Comment

by:abstractionz
ID: 12677884
it runs fine via Eclipse
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677890
... but that  wouldn't work if you've not got a corresponding package structure
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 12677892
java -classpath f:\code\lp\bin example.Main
0
 
LVL 92

Expert Comment

by:objects
ID: 12677896
and if you want a jar, see the command I posted earlier to create it :)
0
 

Author Comment

by:abstractionz
ID: 12677899
thank you that worked
0
 
LVL 92

Expert Comment

by:objects
ID: 12677902
good stuff :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677904
I'm getting confused now - the point of this is to use a jar is it not abstractionz ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677909
What did that have to do with a jar?
0
 
LVL 92

Expert Comment

by:objects
ID: 12677918
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
 

Author Comment

by:abstractionz
ID: 12678107
i tried running

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

but when i run lp.jar i get a NoClassDefFoundError
0
 

Author Comment

by:abstractionz
ID: 12678112
in the manifest was

Main-Class: example.Main
0
 
LVL 92

Expert Comment

by:objects
ID: 12678124
try:

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

0
 

Author Comment

by:abstractionz
ID: 12678133
get the same error
0
 
LVL 92

Expert Comment

by:objects
ID: 12678150
post the contents of your jar using:

jar tvf lp.jar
0
 

Author Comment

by:abstractionz
ID: 12678160
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
 
LVL 92

Expert Comment

by:objects
ID: 12678167
cd to f:/code/lp/bin and try

jar cmf mymanifest lp.jar example
0
 

Author Comment

by:abstractionz
ID: 12678170
that worked.  thanks again.
0
 
LVL 92

Expert Comment

by:objects
ID: 12678177
no worries :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question