Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-30-2008, 12:31 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
".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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-30-2008, 01:22 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-01-2008, 10:57 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-05-2008, 10:00 AM
Cnu Cnu is offline
Member
 
Join Date: Feb 2008
Posts: 13
Cnu is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-05-2008, 12:05 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Thank you
Thank you, Cnu, that really helps!
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 02-05-2008, 10:59 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 02-06-2008, 03:54 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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

Code:
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?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 02-06-2008, 05:07 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
The Deployment trail in the tutorial has a good lesson on jar files: Lesson: Packaging Programs in JAR Files.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 02-06-2008, 10:24 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 02-07-2008, 01:09 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to 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.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 02-07-2008, 11:52 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Manifest
Quote:
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:
Code:
Main-Class: pack.Main
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:
Code:
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.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 02-08-2008, 01:06 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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?
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 02-08-2008, 01:23 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Hello gibsonrocker800.

Quote:
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.
Quote:
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"
Quote:
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.
Attached Files
File Type: zip C drive.zip (23.5 KB, 1 views)
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows ".exe" files tim New To Java 3 12-28-2007 11:25 PM
Hwlp with "Open", "Save", "Save as..." trill New To Java 1 07-31-2007 09:53 AM
Exception in thread "main" java.net.ConnectException: Connection timed out osval Advanced Java 1 07-28-2007 12:59 AM
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException romina New To Java 1 07-26-2007 12:55 AM
ArrayList: Exception in thread "main" java.lang.NullPointerException susan New To Java 1 07-16-2007 08:32 AM


All times are GMT +3. The time now is 04:59 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org