Solved

URGENT! JAR FILE HELP

Posted on 2004-10-11
31
555 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
ID: 12283285
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
ID: 12283506
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
ID: 12283614
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:polkadot
ID: 12284193
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
ID: 12284212
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
ID: 12284217
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
ID: 12284223
0
 

Author Comment

by:polkadot
ID: 12284278
what the hell is ant?

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

Expert Comment

by:Giant2
ID: 12284287
>... 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
ID: 12284299
no! I have read that and I can't figure it out
0
 
LVL 92

Expert Comment

by:objects
ID: 12284314
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
ID: 12284318
the command is:
jar cf Thejar-file Theinput-file(s)
is it working?
0
 

Author Comment

by:polkadot
ID: 12284325
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
ID: 12284354
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
ID: 12284361
whops.
jar cmf META-INF/MANIFEST.MF googleapi.jar *
0
 

Author Comment

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

Author Comment

by:polkadot
ID: 12284371
I mean mymain.jar

0
 
LVL 12

Expert Comment

by:Giant2
ID: 12284422
>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
ID: 12284439
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
ID: 12284444
P.S. leave a blank line after the Class-Path:...
0
 

Author Comment

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

Expert Comment

by:Giant2
ID: 12284502
please post your manifest file
0
 

Author Comment

by:polkadot
ID: 12284534
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
ID: 12284559
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
ID: 12284587
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
ID: 12284594
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
ID: 12284597
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
ID: 12284663
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
ID: 12284764
YAY!! thanks so much! it worked!
0
 
LVL 12

Expert Comment

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

Expert Comment

by:Giant2
ID: 12285022
thanks!
Happy to help you.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
micro services spring boot application error 3 197
null output 3 25
login form jsp example 2 26
Java: anonymous class 4 22
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

803 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