Solved

JAR

Posted on 2003-11-19
22
869 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
difference of if loops 23 50
jdbc error in jsp application 20 47
runtime exception 2 30
CSV file parsing thru Java 13 31
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 …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

832 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