|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

01-30-2008, 12:31 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
".jar" files
Hello everyone
I want to learn how to create ".jar" archives by using the jar program in Command Prompt. It will be great if someone could give me an example of how a folder of ".class" files, including the class with the main() method, can be placed into a ".jar" file using the Command Prompt for Windows.
Thank you. 
__________________
If your ship has not come in yet then build a lighthouse.
Last edited by tim : 01-30-2008 at 10:34 AM.
|
|

01-30-2008, 01:22 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
I would also like to know how to do this. It is to my understanding that, if i turn a program into a .jar, i will be able to send it to friends and they can execute my program via double-click (if they have JRE). So, yeah, if someone could help us out that would be awesome!
__________________
//Haha javac, can't see me now, can ya?
|
|

02-01-2008, 10:57 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
Refresh thread
Hello everyone.
I just want to refresh my question for gibsonrocker800 and me.
Thank you. 
__________________
If your ship has not come in yet then build a lighthouse.
|
|

02-05-2008, 10:00 AM
|
|
Member
|
|
Join Date: Feb 2008
Posts: 13
|
|
|
let us assume you have 3 java files in a folder say Cnu
as
One.java
Two.java
Three.java
and code is as follows.
One.java
=======
class One
{}
Two.java
======
class Two
{
}
Three.java
========
class Three
{
public static void main(String[] args)
{
System.out.println("Three");
}}
place all these files in CNU folder after that compile all java classes.
after that create a jar file called example.jar as
c:\cnu\jar -cf example.jar
after that create a file called manifest file .manifest file is a file where we store information about the classes having main().
maniClass.txt(manifest file)
========
Main-Class : Three
(Note Three is the name of the class having main().You can mention either Three or Three.class but not Three.java)
after that
c:\cnu\jar -cmf example.jar *.class mainClass.txt
if we want to execute our jar files type the follwoing command
c:\cnu\java -jar example.jar
then u will get output as "Three"
Try this one
|
|

02-05-2008, 12:05 PM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
Thank you
Thank you, Cnu, that really helps! 
__________________
If your ship has not come in yet then build a lighthouse.
|
|

02-05-2008, 10:59 PM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
Extra information
Hello everyone.
I'm sorry for the double post, but I've done some reading about this topic in a Wikipedia article. I've learned that is important to end your manifest file with either a new line or carriage return.
Thank you. 
__________________
If your ship has not come in yet then build a lighthouse.
|
|

02-06-2008, 03:54 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
Hey guys, here's how I'm doing it. Without any newline. You can set the manifest right in the creation of the jar
So, say i have two classes: Example, and ExampleTester (which has main)
at the command line, we set the path to the location of these classes. Then we say
jar cfe ExampleJar.jar ExampleTester ExampleTester.class Example.class
the ExampleJar.jar is the new Jar to be created
ExampleTester specifies the main class.
ExampleTester.class and Example.class specify the two files to put in the jar.
This works perfectly for me!
__________________
//Haha javac, can't see me now, can ya?
|
|

02-06-2008, 10:24 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
Manifest
Hello gibsonrocker800
The reason that I want to use a self-defined manifest file, is because I might want to add other information, like libraries for example Java3D or XOM.  You also made a duplicate post. Just edit the second one and delete it. 
__________________
If your ship has not come in yet then build a lighthouse.
|
|

02-07-2008, 01:09 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
Sorry for the double-post tim, my internet was being slow and not working so i clicked post twice.
But yeah about the manifest, i had trouble doing it that way. It didn't work for me. I don't know, i'll try it out again.
__________________
//Haha javac, can't see me now, can ya?
|
|

02-07-2008, 11:52 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
Manifest
Originally Posted by gibsonrocker800
Sorry for the double-post tim, my internet was being slow and not working so i clicked post twice.
But yeah about the manifest, i had trouble doing it that way. It didn't work for me. I don't know, i'll try it out again.
No problem. I have a slow connection, so I know have you feel. My manifest file is located in the class path folder and it looks like this:
Note that it ends with a new line. All my classes are in a folder called "pack", hence they are part of the "pack" package. My batch file looks like this:
SET PATH=C:\Program Files\Java\jdk1.6.0_01\bin\
SET CLASSPATH=C:\java\
cd c:\java\pack\
javac *.java
cd c:\java
jar -cfm run.jar manifest.MF pack\*.class
java -jar run.jar
cd c:\java\
I hope this helps you gibsonrocker800! Cheers 
__________________
If your ship has not come in yet then build a lighthouse.
|
|

02-08-2008, 01:06 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
A few questions on this
How do you create a manifest file (with .MF)
How do you put a newline in the file.
I'm confused about where to put the files.
__________________
//Haha javac, can't see me now, can ya?
|
|

02-08-2008, 01:23 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
Hello gibsonrocker800.
Originally Posted by gibsonrocker800
How do you create a manifest file (with .MF)
I use notepad in Windows XP. I then save it as a normal text file. Make sure that in your folder options, under the "view" tab, that the "Hide extendsions for known file types" is not ticked. You should see the name of the manifest file to be "manifest.txt". Just rename it to "manifest.MF". I think that you can also pass a normal ".txt" file as a manifest file.
Originally Posted by gibsonrocker800
How do you put a newline in the file.
When you typed your last line and the cursor is still on that line, press "enter". In Java, this will look like a String instance: "Main-Class: pack.Main \n"
Originally Posted by gibsonrocker800
I'm confused about where to put the files.
See my attachment and then you can see where I have all my files. Just extract it in your C drive.
Good luck. 
__________________
If your ship has not come in yet then build a lighthouse.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|