Link to home
Start Free TrialLog in
Avatar of richardsimnett
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
Avatar of petmagdy
petmagdy
Flag of Canada image

do this on ur code root directory
% 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
Avatar of kiranhk
kiranhk

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
Avatar of Mick Barry
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
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
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/ .


Avatar of richardsimnett

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\Desktop\websites\mailpro\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
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Objects,
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)
see the tutorial i posted above for a run down.