Solved

JAR

Posted on 2003-11-19
22
865 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now