Solved

URGENT! JAR FILE HELP

Posted on 2004-10-11
31
538 Views
Last Modified: 2008-02-26
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
Comment
Question by:polkadot
  • 14
  • 11
  • 3
  • +3
31 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
 
LVL 16

Expert Comment

by:suprapto45
Comment Utility
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
 
LVL 3

Expert Comment

by:CI-Ia0s
Comment Utility
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
 

Author Comment

by:polkadot
Comment Utility
thats the problem i have folders of packages in those direcories too what can i do about it?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
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
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
0
 

Author Comment

by:polkadot
Comment Utility
what the hell is ant?

and why can't anyone give me the command that will work?
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
>... anyone give me the command that will work
see here:
http://java.sun.com/docs/books/tutorial/jar/basics/index.html
0
 

Author Comment

by:polkadot
Comment Utility
no! I have read that and I can't figure it out
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
the command is:
jar cf Thejar-file Theinput-file(s)
is it working?
0
 

Author Comment

by:polkadot
Comment Utility
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
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
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
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
whops.
jar cmf META-INF/MANIFEST.MF googleapi.jar *
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:polkadot
Comment Utility
no the file i want to produce is mymain.class .. i am just using the googleapi
0
 

Author Comment

by:polkadot
Comment Utility
I mean mymain.jar

0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
>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
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
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
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
P.S. leave a blank line after the Class-Path:...
0
 

Author Comment

by:polkadot
Comment Utility
nope not solved getting a different error now: main class not found
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
please post your manifest file
0
 

Author Comment

by:polkadot
Comment Utility
Manifest-Version: 1.0
Created-By: 1.3.1_01 (Sun Microsystems Inc.) and me
Main-Class: mymain.class
Class-Path: ./googleapi.jar
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
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
 

Author Comment

by:polkadot
Comment Utility
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
 
LVL 5

Expert Comment

by:Naeemg
Comment Utility
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
 

Author Comment

by:polkadot
Comment Utility
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
 
LVL 12

Accepted Solution

by:
Giant2 earned 500 total points
Comment Utility
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
 

Author Comment

by:polkadot
Comment Utility
YAY!! thanks so much! it worked!
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
>it worked!
So now you can close this thread, or not?
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
thanks!
Happy to help you.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now