• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 591
  • Last Modified:

URGENT! JAR FILE HELP

I have a directoy of java classes, I have a main class lets call it MyProgram.class and a buch of other classes main depends on in a folder called MyFolder ... what is the command for jar to create a jar file with all of these?

I have tried to read and understand the help files in java.com .. but Its not working keep getting manifest error and I have a manifest file called manifest with the follwing : Main-Class: MyProgram.class

and the manifest file is in the folder MyFolder ...


and for some reason I an only run jar for the directory C:\j2sdk1.4.2_05\bin  ... something was messed up during install maybe so what would the command be?

C:\j2sdk1.4.2_05\bin> (what command goes here)
0
polkadot
Asked:
polkadot
  • 14
  • 11
  • 3
  • +3
1 Solution
 
objectsCommented:
assuming the classes aren't in package, go to the directory containing your classes and run:

C:\j2sdk1.4.2_05\bin\jar cvmf manifest.mf my.jar *.class
 
0
 
suprapto45Commented:
Hi,

I do not know but this URL really helps me on creating jar files and please pay attention on "jar cvf TicTacToe.jar *". The content is self-explanatory (I think :D ).

http://java.sun.com/docs/books/tutorial/jar/basics/build.html

I hope that helps. If not, can you tell me more specifically your scenario?
0
 
CI-Ia0sCommented:
You can optionally create the JAR file separately and add the manifest later (it doesn't make a big difference, but it's how I do it usually *shrug*):
jar cfv myJar.jar *.class
jar umfv myManifest.txt myJar.jar

>>and for some reason I an only run jar for the directory C:\j2sdk1.4.2_05\bin  ... something was messed up during install maybe so what would the command be?

You need to set your PATH system variable to include the location of the SDK bin folder. I believe you just put a semicolon on the end of whatever's there now and add in the path, but I'm not sure as I'm usually on a Mac. ;)
I believe you can find that variable by getting the properties of "My Computer" and then going to "Advanced", then "Environment Variables". I'm not sure though as I don't have a PC in front of me at the moment to check. ;)
0
Technology Partners: 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!

 
polkadotAuthor Commented:
thats the problem i have folders of packages in those direcories too what can i do about it?
0
 
objectsCommented:
i'd suggest using ant, it'll take you a bit longer to get going but in the long run you'll save lots of time.

0
 
Giant2Commented:
to specify the path:
set PATH=%PATH%;put here your paths separated by ;

to specify the classpath:
set CLASSPATH=%CLASSPATH%;your classpaths separated by ;

Giant.
0
 
polkadotAuthor Commented:
what the hell is ant?

and why can't anyone give me the command that will work?
0
 
Giant2Commented:
>... anyone give me the command that will work
see here:
http://java.sun.com/docs/books/tutorial/jar/basics/index.html
0
 
polkadotAuthor Commented:
no! I have read that and I can't figure it out
0
 
objectsCommented:
use the following listing ant directories you want included:

C:\j2sdk1.4.2_05\bin\jar cvmf manifest.mf my.jar dir1 dir2

specify the base directory package hierarchy.

ant is a build tool:

http://ant.apache.org/
0
 
Giant2Commented:
the command is:
jar cf Thejar-file Theinput-file(s)
is it working?
0
 
polkadotAuthor Commented:
here is the thing... I am using the googleapi.. so

I have:

googleapi.jar
mymain.class
mymain$ExitListener.class
mymain$.class
other.class
other2.class
manifest.mf



the googleapi.jar i have decompressed into folders and i've tried with or without them there it doesn't work keeps giving me same error ... fialed to load Main-Class manifest ...

mainifest.mf is simply :
Manifest-Version: 1.0
Main-Class: mymain.class


0
 
Giant2Commented:
manifest file must be in this position:
META-INF/MANIFEST.MF
here the classes:
mymain.class
mymain$ExitListener.class
mymain$.class
other.class
other2.class

and this the command:
jar cMf googleapi.jar *

the file you want to produce is the googleapi.jar, isn't it?
0
 
Giant2Commented:
whops.
jar cmf META-INF/MANIFEST.MF googleapi.jar *
0
 
polkadotAuthor Commented:
no the file i want to produce is mymain.class .. i am just using the googleapi
0
 
polkadotAuthor Commented:
I mean mymain.jar

0
 
Giant2Commented:
>no the file i want to produce is mymain.class .. i am just using the googleapi
>I mean mymain.jar

ok.

jar cmf META-INF/MANIFEST.MF mymain.jar *
0
 
Giant2Commented:
if you want to referring from the classes in your jar to the classes contained in the googleapi.jar you must add this line to your manifest file:
Class-Path: ./googleapi.jar

I think now your problem is solved. Isn't it?
0
 
Giant2Commented:
P.S. leave a blank line after the Class-Path:...
0
 
polkadotAuthor Commented:
nope not solved getting a different error now: main class not found
0
 
Giant2Commented:
please post your manifest file
0
 
polkadotAuthor Commented:
Manifest-Version: 1.0
Created-By: 1.3.1_01 (Sun Microsystems Inc.) and me
Main-Class: mymain.class
Class-Path: ./googleapi.jar
0
 
Giant2Commented:
A question:
your mymain.class isn't part of a package.
I mean in your mymain.java you have not:
package somepackage
...
class mymain....

Isn't it?

Because if the Manifest file is inserted correctly in your jar, seems the mymain class is not reachable (maybe in a different package).
0
 
polkadotAuthor Commented:
these are all seperate files:

mymain.class
mymain$ExitListener.class
mymain$.class
other.class
other2.class

created from sepearted files:
mymain.java
other.java
other2.java

I use the googleapi package by doing "import com.google.soap.search.*;" at the begingin of mymain.java
0
 
NaeemgCommented:
hi, follow the directions.

//open notepad save the following lines in "MANIFEST.MF" file, make sure while saving u've selected file type as All files and gave file extension as MF"

Manifest-Version: 1.0
Main-Class: YourMainClass
Created-By: 1.4.0-beta (Sun Microsystems Inc.)

//now save the following lines in "MakeJar.bat" file

jar cvfm newFile.jar MANIFEST.MF googleapi.jar mymain.class
mymain$ExitListener.class
mymain$.class
other.class
other2.class
manifest.mf


//Naeem Shehzad Ghuman
0
 
polkadotAuthor Commented:
META-INF/MANIFEST.MF means that it is in a directory under the one im in

for example all the files above contained in c:\temp

c:\temp\META-INF\MANIFEST.MF is location of manifest right?

I have all the googleapi stuff there too and META-INF\MANIFEST was the googleapi manifest I just added to it, right?
0
 
Giant2Commented:
ok! I understand.
I believe you must insert a . to the classpath; so the manifest could be:
...
Main-Class: mymain.class
Class-Path: .;./googleapi.jar
0
 
polkadotAuthor Commented:
YAY!! thanks so much! it worked!
0
 
Giant2Commented:
>it worked!
So now you can close this thread, or not?
0
 
Giant2Commented:
thanks!
Happy to help you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 14
  • 11
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now