Solved

JAR

Posted on 2003-11-19
22
862 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
Comment Utility
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
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
Comment Utility
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
Comment Utility
make sure you have a couple of blank lines at the end of your manifest
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
increase some points
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
c:\jdk1.4.2\javac\bin\java -jar Filename.jar

should be like :

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

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Author Comment

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

Author Comment

by:InNoCenT_Ch1ld
Comment Utility
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
Comment Utility
>> 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
Comment Utility
> Main-Class : MainFrame

get rid of the space before the colon

Main-Class: MainFrame
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
Me = Christian,
Javatm = Christian too?
;)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
>> 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

743 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

17 Experts available now in Live!

Get 1:1 Help Now