Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 03-03-2008, 11:56 PM
Member
 
Join Date: Feb 2008
Posts: 12
Deathmonger is on a distinguished road
Creating .Jar files
Hi, I know this topic has been created in a thread before, but I still can't seem to be able to create JAR files. If someone can please help me with a step-by-step process, or tell me what I'm doing wrong, that would be great.

I'm creating a simple Slots game, and want to create it as an executable. I have my code in one file "Slots.java" and two classes in this file, "Slots.class" and "Slots$Play.class." The classes are packeged under Package Slots; I also created a manifest file which contains "Main-Class: Slots.Slots." I also added a carriage return after that line. All these files are included in the folder ...bin2/Slots/.

I try to create the jar file through command prompt. After compiling Slots.java and making sure teh program works, I'm not to sure how to create the jar file.

Here is the code that I used for Slots.java:

Code:
package Slots; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class Slots { static JFrame frame; static Container container; static JTextField bet; static JLabel winnings; static JLabel balance; static JLabel slot1; static JLabel slot2; static JLabel slot3; static JButton ride; static double userBalance = 50; static double userBet; static String firstSlot; static String secondSlot; static String thirdSlot; static int one; static int two; static int three; static double temp; static class Play implements ActionListener { public void actionPerformed(ActionEvent ae) { userBet = Double.parseDouble(bet.getText()); temp = userBet; RoleSlots(); WinorLose(); slot1.setText(firstSlot); slot2.setText(secondSlot); slot3.setText(thirdSlot); balance.setText("" + userBalance); winnings.setText("" + temp); } public void RoleSlots() { String outcomes[] = {"BAR", "CHERRY", "7", "BELL"}; one = (int)(Math.random() * 3); two = (int)(Math.random() * 3); three = (int)(Math.random() * 3); firstSlot = outcomes[one]; secondSlot = outcomes[two]; thirdSlot = outcomes[three]; } public void WinorLose() { switch(one) { case(0) : switch(two) { case(0) : switch(three) { case(0) : userBalance += userBet * 3; break; } } case(1) : switch(two) { case(1) : switch(three) { case(0) : userBalance += userBet * 0.5; break; case(1) : userBalance += userBet * 1; break; case(2) : userBalance += userBet * 0.5; break; case(3) : userBalance += userBet * 0.5; break; } } case(2) : switch(two) { case(2) : switch(three) { case(2) : userBalance += userBet * 4; break; } } case(3) : switch(two) { case(3) : switch(three) { case(0) : userBalance += userBet * 1; break; case(1) : userBalance += userBet * 1; break; case(2) : userBalance += userBet * 1; break; case(3) : userBalance += userBet * 2; } } default : userBalance -= userBet; } } } public static void main(String[] args) { frame = new JFrame(); container = new Container(); bet = new JTextField(); winnings = new JLabel(); balance = new JLabel("Balance Shown Here"); slot1 = new JLabel(); slot2 = new JLabel(); slot3 = new JLabel(); ride = new JButton("Ride"); Play p = new Play(); ride.addActionListener(p); frame.setSize(500,500); container = frame.getContentPane(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); container.setLayout(new GridLayout(3,3)); container.add(bet); container.add(winnings); container.add(balance); container.add(slot1); container.add(slot2); container.add(slot3); container.add(ride); frame.setVisible(true); } }
Here is the content of mainClass (The manifest file):

Main-Class: Slots.Slots

I've tried using in command prompt "jar cmf mainClass Slots.jar Slots.class Slots

All files are located in ...java/jdk1.6.0_02/bin2/Slots/. I also tried various variations for jar, and I'm still unable to create a working jar file. Someone please help me. Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-04-2008, 03:10 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 do it a different way. The way you're doing it is probably the better way. But mine, you don't need to create a manifest file. You just have to specify the main class. For example.

If i had two classes ExampleMain (who contains main()) and Example
Here is how i would do it at the command line

Code:
jar cfe MyJar.jar ExampleMain ExampleMain.class Example.class
the segment: ExampleMain tells it which class contains main().

Let me know how this works out for you.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-04-2008, 07:00 PM
Member
 
Join Date: Feb 2008
Posts: 12
Deathmonger is on a distinguished road
Ok, This is what I typed in:

jar cfe SlotsGame.jar Slots Slots.class Slots$Play.class

This creates a Jar file. Thanks for helping me get past that part. Now what can I do with the jar file. If I execute the jar file, should I be able to run the program??
__________________
Jai guru deva om, Nothing's gonna change my world
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-04-2008, 09:22 PM
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
Well that really depends. If it is a console application (uses System.out.println() and Scanners), it cannot be executed via double-click. However, it can be executed by the following command, in a DOS window.

Code:
java -jar SlotsGame.jar
Now, on the other hand, if it is graphical, you can run it via double-click, and of course you can use the above command.

Oh and I'm glad i could help you create your jar.

Here's something that i thought was a really cool idea. I made a program which makes jars for the user (after they specify a few things). The way it does it, is that it creates a MS-DOS batch file which executes the commands i showed you, thus created a .jar file. It's pretty cool, if anyone would like me to send them the finished program (which is a jar program =]), I'd be glad to. (i just gotta finish up a few things, like a user manual)
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 03-10-2008, 04:48 PM
Member
 
Join Date: Feb 2008
Posts: 12
Deathmonger is on a distinguished road
Does having JButtons and a JFrame count as having a graphical program? Because when I run the .jar executable file, nothing happens.
__________________
Jai guru deva om, Nothing's gonna change my world
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 03-17-2008, 04:43 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
Hmm... I'm actually not too sure on that. Anyone else know more information on this?
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-23-2008, 12:59 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 145
Nicholas Jordan is on a distinguished road
Console or window - don't be judgmental.
Well, I have put up a Window - a true, actual graphical window as we all know it - from a console program that was actually already running. Whether one could get a console window to popup from a True Graphical, I neither know nor care. I design my programs with the idea that anything the user can see or point at in the routine use of the computer counts as User Interface, thus an actual file created by a running program counts ~ generally ~ in the broadest scope as a user interface.

Having javax.swing.anything makes the program 'graphical' if we want to call it that. Writing only to System.out and to files created by the program generally puts it in the Console Program category. Either way, making a jar file that the intended users can run as a program is done by having one class that has a public static void main(String[].... and that is invoked by the Java Runtime, aka jvm or Java Virtual Machine. It may be that graphical ( true gui programs that are neither Console nor silent utilities ) are runnable by javaw without the console window hanging around on the screen.

We do however need an investment of some effort on the part of the user.

We have a file named .jar in which there is a directory named mainfest-mf or something.

In that directory there is a file called mainfest.mf ~ you open it and add the lines :
Code:
Main-Class: (the name of your class that has the main() method)
OR

Code:
Main-Class: pack.ClassName
Where pack.ClassName is your package name and main() class name.

Even with that, the intended user has to be able to understand your directions given.

See: Notes about the Java Programming Language

by:
Ryan Stansifer
Last modified: Tue Feb 20 14:37:17 EST 2007
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
Creating JAR files - 2 JavaForums Java Blogs 0 04-14-2008 06:11 PM
Creating JAR files - 1 JavaForums Java Blogs 0 04-14-2008 02:10 PM
Creating ZIP files Java Tip Java Tips 0 03-03-2008 06:14 PM
Creating JAR files JavaForums Java Blogs 0 12-24-2007 01:30 PM
Creating ZIP files JavaForums Java Blogs 0 12-21-2007 11:40 AM


All times are GMT +3. The time now is 10:47 AM.


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