richardsimnett
asked on
Really Stupid... but how do I create a jar file?
Hello,
I feel really dumb for asking this question. But can someone give me a step by step to create a jar file from a set of classes. Everytime I try to I end up with manifest problems, and have been unable to successfully create a jar file.
Cheers,
Rick
I feel really dumb for asking this question. But can someone give me a step by step to create a jar file from a set of classes. Everytime I try to I end up with manifest problems, and have been unable to successfully create a jar file.
Cheers,
Rick
first have your path pointed to JDK/bin directory
then execute this command
jar -cvf yourjarname.jar yourfolder or .
like
jar -cvf test.jar .
jar -cvf test.jar c:\test
then execute this command
jar -cvf yourjarname.jar yourfolder or .
like
jar -cvf test.jar .
jar -cvf test.jar c:\test
grab a copy of ant, it'll handle all your build tasks for you.
>>Everytime I try to I end up with manifest problems
What kind?
jar cfm yourfile.jar yourman.mf *.class
What kind?
jar cfm yourfile.jar yourman.mf *.class
Another low-tech way to do it is to add your .class files to a .zip file using WinZip or other compression program and then rename the .zip file to a .jar file.
Almost seems too simple but it works :-)
Cheers,
Jonathan
Almost seems too simple but it works :-)
Cheers,
Jonathan
the easiest way to learn by itself is first add ur jdk/bin path in ur PATH variable. next type only jar on the command prompt and enter. It will list you all the options and th required parameters, so that you can play around with it.
Example:
If you want to add two classes A.java and B.java into the jar file named Sample.jar, execute:
jar cvf Sample.jar A.java B.java
If you want to use an existing manifest file, named as testmanifest, and want to archive all the files in the folder test into Sample.jar, execute:
jar cvfm Sample.jar testmanifest -C test/ .
Example:
If you want to add two classes A.java and B.java into the jar file named Sample.jar, execute:
jar cvf Sample.jar A.java B.java
If you want to use an existing manifest file, named as testmanifest, and want to archive all the files in the folder test into Sample.jar, execute:
jar cvfm Sample.jar testmanifest -C test/ .
ASKER
Hey guys,
Sorry about the dealy in responding to your posts. I have tried all of the above methods.. and all result in the same error:
C:\Documents and Settings\Administrator\Des ktop\websi tes\mailpr o\MPFeeder >java -
jar mpfeeder
Failed to load Main-Class manifest attribute from
mpfeeder
This is the same result as I have always gotten. What am I doing wrong here?
Cheers,
Rick
Sorry about the dealy in responding to your posts. I have tried all of the above methods.. and all result in the same error:
C:\Documents and Settings\Administrator\Des
jar mpfeeder
Failed to load Main-Class manifest attribute from
mpfeeder
This is the same result as I have always gotten. What am I doing wrong here?
Cheers,
Rick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Objects,
Doesnt java automatically generate a manifest? I havent written one.. dont really know how either....
Cheers,
Rick
Doesnt java automatically generate a manifest? I havent written one.. dont really know how either....
Cheers,
Rick
It does, but it doesn't include the Main-Class: attribute required for it to be executable.
(As it has no way of knowing which class should be run, if any)
(As it has no way of knowing which class should be run, if any)
see the tutorial i posted above for a run down.
% jar cf myjarfile *.class
a jar named myjarfile.jar will be generated
but first make sure that ur JDK bin directory is in ur PATH enviroment