[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

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
0
richardsimnett
Asked:
richardsimnett
1 Solution
 
petmagdyCommented:
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
0
 
kiranhkCommented:
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
0
 
objectsCommented:
grab a copy of ant, it'll handle all your build tasks for you.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
>>Everytime I try to I end up with manifest problems

What kind?

jar cfm yourfile.jar yourman.mf *.class
0
 
objectsCommented:
0
 
JonathanJonasCommented:
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
0
 
kupra1Commented:
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/ .


0
 
richardsimnettAuthor Commented:
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
0
 
objectsCommented:
Try adding a couple of lines to the bottom of your manifest file
And make sure your manifest contains the Main-Class attribute

0
 
richardsimnettAuthor Commented:
Objects,
Doesnt java automatically generate a manifest? I havent written one.. dont really know how either....

Cheers,
Rick
0
 
objectsCommented:
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)
0
 
objectsCommented:
see the tutorial i posted above for a run down.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now