
-----------------------------------
jin
Wed Jun 22, 2005 5:04 pm

Need help creating jar files
-----------------------------------
Hi i am using "Ready to Program" to make java programs. I have made a programs called "database.java" and want to make it into a jar file so i can open the database without using"Ready to Program".

-----------------------------------
wtd
Wed Jun 22, 2005 5:18 pm


-----------------------------------
If you're using a lower-case letter at the beginning of a class, then you're not following the Java style guidelines.  ;)

-----------------------------------
1of42
Wed Jun 22, 2005 9:52 pm


-----------------------------------
If you're using a lower-case letter at the beginning of a class, then you're not following the Java style guidelines.  ;)

Or you could tell him how to do it... :roll: 

But to the original poster: there is a thread [url=http://www.compsci.ca/v2/viewtopic.php?t=6945]here about how to do it.

-----------------------------------
wtd
Wed Jun 22, 2005 11:05 pm


-----------------------------------
Well, in case you're thinking I'm just a jerk... I'm not.  I simply like to point out mistakes.  

"Right, because you're a jerk..."

You're likely tempted to think so, but that's still not right.  What jin is asking to do is not a first week kind of thing.  Before anyone moves on, they should have the intro stuff down.  Clearly that's not the case.

Fail early, fail often, and fail hard.  Continuing to program without being told that you're doing simple things wrong just reinforces bad habits.

-----------------------------------
Naveg
Fri Jun 24, 2005 6:26 am


-----------------------------------
Let me tell you, trust wtd. He's done more for my programming skills than my compsci teacher did this year. And believe me he knows what he's talking about.

-----------------------------------
jin
Fri Jun 24, 2005 9:29 am


-----------------------------------
sorry bout the name it is "Database.java".i looked at that thread and i dont get it. it says type "java -jar filename.jar" in command prompt and next poster is talking bout a manifest file. 
could someone explain to me wat to do step by step.

-----------------------------------
1of42
Fri Jun 24, 2005 3:40 pm


-----------------------------------
The way I did it was to put all the class files I needed into the bin directory in the j2sdk directory. Also put in a manifest file, which should read something like this:


Manifest-Version: 1.2
Created-By: 1.4.2_04 (Sun Microsystems Inc.)
Main-Class: YourMainClassHere(No .class extension)


Make sure there is a new line after the main-class. Call the file manifest.txt or something. Then use the following command line command to make a jar

jar -cvmf manifest.txt .jar [List of class files]

-----------------------------------
Hikaru79
Fri Jun 24, 2005 11:29 pm


-----------------------------------
Here's [url=http://java.sun.com/docs/books/tutorial/jar/basics/]everything you need to know about JAR files. But, you don't really need to make it a .jar file to be runnable outside of RTP.

-----------------------------------
jin
Mon Jun 27, 2005 3:54 pm


-----------------------------------
But, you don't really need to make it a .jar file to be runnable outside of RTP.

whats the other way cause creating a jar file is confusing.[/quote]

-----------------------------------
wtd
Mon Jun 27, 2005 3:55 pm


-----------------------------------
But, you don't really need to make it a .jar file to be runnable outside of RTP.

whats the other way cause creating a jar file is confusing.

Install the standard JDK and use that instead?

-----------------------------------
jin
Mon Jun 27, 2005 11:33 pm


-----------------------------------
can you giveme a link from where i can get standard JDK

-----------------------------------
wtd
Tue Jun 28, 2005 12:27 am


-----------------------------------
http://java.sun.com

-----------------------------------
jin
Tue Jun 28, 2005 12:40 pm


-----------------------------------
i installed JDK so how do i open my program using that

-----------------------------------
wtd
Tue Jun 28, 2005 1:31 pm


-----------------------------------
Open a Command Prompt window, move to the directory that contains your class file, and run "java MyProgramName".

-----------------------------------
jin
Tue Jun 28, 2005 8:44 pm


-----------------------------------
i successfully made a jar file using the "jar-cmf" code but that worked for an applet program but not the database program ehich is an application.

is there another code for an application to jar?

-----------------------------------
rizzix
Tue Jun 28, 2005 8:47 pm


-----------------------------------
does ur manifest file include a Main-Class field?

-----------------------------------
jin
Tue Jun 28, 2005 9:00 pm


-----------------------------------
Also "java MyProgramName" worked for applet but gave "Exception in thread "main" java.lang.NoClassDefFoundError: Database/class" for application 

Database is name of program. is there a way around this.

-----------------------------------
jin
Tue Jun 28, 2005 9:01 pm


-----------------------------------
Ya it did have a main class field

-----------------------------------
rizzix
Tue Jun 28, 2005 9:07 pm


-----------------------------------
post ur manifest...

-----------------------------------
jin
Tue Jun 28, 2005 9:22 pm


-----------------------------------
Manifest-Version: 1.0
Created-By: 1.5.0_01 (Sun Microsystems Inc.)
Main-Class: Database.class
Class-Path: F:\Java\Database

-----------------------------------
rizzix
Tue Jun 28, 2005 11:06 pm


-----------------------------------
Manifest-Version: 1.0
Created-By: 1.5.0_01 (Sun Microsystems Inc.)
Main-Class: Database.class
Class-Path: F:\Java\Database

it should be just:Main-Class: Database assuming ur using the default package..

-----------------------------------
jin
Wed Jun 29, 2005 8:33 am


-----------------------------------
i made the change and it created the jar but when i try to open it i get error "Could not find Main-Class. Program will exit".

-----------------------------------
rizzix
Wed Jun 29, 2005 10:21 am


-----------------------------------
obviously that assumes Database has the public static void main(String method.. if it doesn't then it is not the main class.

-----------------------------------
1of42
Wed Jun 29, 2005 1:22 pm


-----------------------------------
obviously that assumes Database has the public static void main(String method.. if it doesn't then it is not the main class.

I bet you that's not the problem... I had this one myself, even though it did have the correct method main signature.

The problem I had was that you must have a newline as the last line in the file; if you don't the manifest doesn't work properly.

-----------------------------------
jin
Fri Jul 01, 2005 11:14 pm


-----------------------------------
Database is the main class and also adding the extra line did not help i still got the error

-----------------------------------
1of42
Fri Jul 01, 2005 11:58 pm


-----------------------------------
weird. a manifest i used that worked:

Manifest-Version: 1.2
Created-By: 1.4.2_04 (Sun Microsystems Inc.)
Main-Class: ReWrite


