Solved

JAR

Posted on 2003-11-19
22
871 Views
Last Modified: 2013-11-23
i intend to create an executable jar file, this is what i do, and what i get...why?
is all my class file need to be put into a package?

D:\ABC>jar cf chooser.jar *.class

D:\ABC>jar chooser.jar manifest.tmp *.class//this doesnt seem work...


Illegal option: h
Usage: jar {ctxu}[vfm0M] [jar-file] [manifest-file] [-C dir] files ...
Options:
    -c  create new archive
    -t  list table of contents for archive
    -x  extract named (or all) files from archive
    -u  update existing archive
    -v  generate verbose output on standard output
    -f  specify archive file name
    -m  include manifest information from specified manifest file
    -0  store only; use no ZIP compression
    -M  do not create a manifest file for the entries
    -i  generate index information for the specified jar files
    -C  change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name and the archive file name needs to be specified
in the same order the 'm' and 'f' flags are specified.

Example 1: to archive two class files into an archive called classes.jar:
       jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all the
           files in the foo/ directory into 'classes.jar':
       jar cvfm classes.jar mymanifest -C foo/ .
0
Comment
Question by:InNoCenT_Ch1ld
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 8
  • 3
22 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 9784187
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9784209
Make sure that when you create a manifest.tmp you include your real main class. Like :

Main-Class : YourMain
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784228
JavaTM, i've read the links you provided already, but when i try it out myself, i got this kind of problem, or my jar wont run! i use javaw and it says that my main class not found?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 9784243
make sure you have a couple of blank lines at the end of your manifest
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784258
i tell you what i've done..

i create a mini app just to try JAR out..
my app has around 3-5 classes.. my mainclass is MainFrame
then i do:

D:\ABC>jar cf chooser.jar *.class

after that, i create a manifest.tmp file, in which i type the only line of:
Main-Class : MainFrame

then i do:
D:\ABC>jar chooser.jar manifest.tmp *.class

and the error comes out..

if i try:
D:\ABC>javaw chooser.jar

it says mainclass not found..why?
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9784269
>> make sure you have a couple of blank lines at the end of your manifest

     :) True, Also make sure that when you are creating your jar file your are
         in the main base directory which has all your classes.
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784287
Now i got this error:

java.io.IOException: invalid header field name: Main-Class
  at java.util.jar.Attributes.read<Attributes.java:362>
  at java.util.jar.Manifest.read<Manifest.java:156>
  at java.util.jar.Manifest.<init><Manifest.java:51>
  at sun.tools.jar.Main.run<Main.java:120>
  at sun.tools.jar.Main.main<Main.java:899>


my manifest.tmp:-
Main-Class : MainFrame

//some blank here..
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784296
all my class files in within the ABC folder..
but all my class don have the package, u know what i mean..(is it the cause of the problem?)

when i run the app using
D:\ABC\java MainFrame

it works...
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9784298
This regard all that you did just create a manifest file then go to your base directory
Then do this :
       
    1.) c:\jdk1.4.2\javac\bin\jar chooser.jar manifest.tmp *.class

         The jdk1.4.2 is the jdk version
        // After that do this :

    2.) c:\jdk1.4.2\javac\bin\java -jar Filename.jar

Hope it helps . .
JAVATM
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784301
increase some points
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9784313
c:\jdk1.4.2\javac\bin\java -jar Filename.jar

should be like :

c:\jdk1.4.2\javac\bin\java -jar chooser.jar

0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784338
Failed to load Main-Class attribute from chooser.jar
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784348
arrgggghhh!!!! this is making me crazy!!!! why all ppl can easily create one executable jar file whereas i have to try out all different ways?... does this mean God is trying to talk to me in some way to ask me to give up doing jar???? :(
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9784359
>> Failed to load Main-Class attribute from chooser.jar

     1.) Try 1st to create a 1 java program or file.
     2.) Make sure you already compile the program.
     3.) Create a manifest.tmp save it on the your main directory.

     4.) On a command promt do this :
          c:\jdk1.4.2\javac\bin\jar chooser.jar manifest.tmp *.class

     5.) After that run the jar like :
          c:\jdk1.4.2\javac\bin\java -jar Filename.jar

Pls. Try this for testing purposes :)
JAVATM
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 9784377
> Main-Class : MainFrame

get rid of the space before the colon

Main-Class: MainFrame
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9784389
>> does this mean God is trying to talk to me
     
     "Walk through the light and he will show you light, Ask and he shall answer,
      Just believe and you'll have a miracle :)"
     
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784390
guys guys, it works!! hahaa....
damn it!! just a bloody idiot space spoil everything!!!

in my manifest.tmp
i type:
Main-Class : MainFrame
               /\
               this is the bloody idiot space!

i remove it and everything ok!

;)
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784397
oppss...
i din notice that objects post the comment oledi.. hehe

so, i accept objects comment, izit ok guys?
;)

-Child-
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784403
Me = Christian,
Javatm = Christian too?
;)
0
 
LVL 92

Expert Comment

by:objects
ID: 9784451
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9784457
>> i accept objects comment, izit ok guys?
     
     You should split points but anways I respect your decision :)
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 9784491
nono... i was thinking just now that i should have post a new empty question for javatm when i was making my cup of coffee.. hahaa..

-Child-
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 58
sql import cannot be resolved jsp 3 74
Glassfish admin console not working 1 56
Java basic valueOf question 1 33
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

756 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