Computer Science Canada

Need help creating jar files

Author:  jin [ Wed Jun 22, 2005 5:04 pm ]
Post subject:  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".

Author:  wtd [ Wed Jun 22, 2005 5:18 pm ]
Post subject: 

If you're using a lower-case letter at the beginning of a class, then you're not following the Java style guidelines. Wink

Author:  1of42 [ Wed Jun 22, 2005 9:52 pm ]
Post subject: 

wtd wrote:
If you're using a lower-case letter at the beginning of a class, then you're not following the Java style guidelines. Wink


Or you could tell him how to do it... Rolling Eyes

But to the original poster: there is a thread here about how to do it.

Author:  wtd [ Wed Jun 22, 2005 11:05 pm ]
Post subject: 

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.

Author:  Naveg [ Fri Jun 24, 2005 6:26 am ]
Post subject: 

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.

Author:  jin [ Fri Jun 24, 2005 9:29 am ]
Post subject: 

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.

Author:  1of42 [ Fri Jun 24, 2005 3:40 pm ]
Post subject: 

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:

code:

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 <JarName>.jar [List of class files]

Author:  Hikaru79 [ Fri Jun 24, 2005 11:29 pm ]
Post subject: 

Here's 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.

Author:  jin [ Mon Jun 27, 2005 3:54 pm ]
Post subject: 

Quote:
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]

Author:  wtd [ Mon Jun 27, 2005 3:55 pm ]
Post subject: 

jin wrote:
Quote:
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?

Author:  jin [ Mon Jun 27, 2005 11:33 pm ]
Post subject: 

can you giveme a link from where i can get standard JDK

Author:  wtd [ Tue Jun 28, 2005 12:27 am ]
Post subject: 

http://java.sun.com

Author:  jin [ Tue Jun 28, 2005 12:40 pm ]
Post subject: 

i installed JDK so how do i open my program using that

Author:  wtd [ Tue Jun 28, 2005 1:31 pm ]
Post subject: 

Open a Command Prompt window, move to the directory that contains your class file, and run "java MyProgramName".

Author:  jin [ Tue Jun 28, 2005 8:44 pm ]
Post subject: 

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?

Author:  rizzix [ Tue Jun 28, 2005 8:47 pm ]
Post subject: 

does ur manifest file include a Main-Class field?

Author:  jin [ Tue Jun 28, 2005 9:00 pm ]
Post subject: 

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.

Author:  jin [ Tue Jun 28, 2005 9:01 pm ]
Post subject: 

Ya it did have a main class field

Author:  rizzix [ Tue Jun 28, 2005 9:07 pm ]
Post subject: 

post ur manifest...

Author:  jin [ Tue Jun 28, 2005 9:22 pm ]
Post subject: 

Manifest-Version: 1.0
Created-By: 1.5.0_01 (Sun Microsystems Inc.)
Main-Class: Database.class
Class-Path: F:\Java\Database

Author:  rizzix [ Tue Jun 28, 2005 11:06 pm ]
Post subject: 

jin wrote:
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:
code:
Main-Class: Database
assuming ur using the default package..

Author:  jin [ Wed Jun 29, 2005 8:33 am ]
Post subject: 

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".

Author:  rizzix [ Wed Jun 29, 2005 10:21 am ]
Post subject: 

obviously that assumes Database has the public static void main(String[] args) method.. if it doesn't then it is not the main class.

Author:  1of42 [ Wed Jun 29, 2005 1:22 pm ]
Post subject: 

rizzix wrote:
obviously that assumes Database has the public static void main(String[] args) 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.

Author:  jin [ Fri Jul 01, 2005 11:14 pm ]
Post subject: 

Database is the main class and also adding the extra line did not help i still got the error

Author:  1of42 [ Fri Jul 01, 2005 11:58 pm ]
Post subject: 

weird. a manifest i used that worked:

code:
Manifest-Version: 1.2
Created-By: 1.4.2_04 (Sun Microsystems Inc.)
Main-Class: ReWrite



: