Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Jar Bundler

Jar Bundler
Thread Tools
Mac Elite
Join Date: Jun 2004
Status: Offline
Reply With Quote
Jul 26, 2004, 01:34 AM
 
I just wrote my first java app with a GUI. I run it from the terminal and everything goes fine. I was looking around, and found the jar bundler, and I want to know how to use it to create an actual app that I can just put in my applications folder and use like a regular program instead of having to use the terminal.
If I wasn't specific enough or you need details on the program or anything, just let me know and I'll give you all the information you need.
Thanks in advance for the help.
Brandon
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 26, 2004, 09:49 AM
 
Originally posted by brandon420506:
I just wrote my first java app with a GUI. I run it from the terminal and everything goes fine. I was looking around, and found the jar bundler, and I want to know how to use it to create an actual app that I can just put in my applications folder and use like a regular program instead of having to use the terminal.
If I wasn't specific enough or you need details on the program or anything, just let me know and I'll give you all the information you need.
Thanks in advance for the help.
Brandon
It's pretty easy. All you do is create a jar file and write the MANIFEST.MF file yourself when you create the jar. In the Manifest, you need this:

Manifest-Version: 1.0
Main-Class: net.theresistance.simpleClass

Setting "Main-Class" will run the main() method of the specified class.

To create the jar in the Terminal, do the following:

Code:
jar -cfm myJarFile myManifestFile *.class
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Nodnarb  (op)
Mac Elite
Join Date: Jun 2004
Status: Offline
Reply With Quote
Jul 26, 2004, 12:52 PM
 
Originally posted by Arkham_c:
It's pretty easy. All you do is create a jar file and write the MANIFEST.MF file yourself when you create the jar. In the Manifest, you need this:

Manifest-Version: 1.0
Main-Class: net.theresistance.simpleClass

Setting "Main-Class" will run the main() method of the specified class.

To create the jar in the Terminal, do the following:

Code:
jar -cfm myJarFile myManifestFile *.class
I'm sorry, as I said, I'm pretty new at programming. I didn't really get what you were saying. I thought I did and I tried it but it didn't work. Do you think you could explain it a little easier, like step by step?
Sorry for the inconvienience.
thanks
brandon
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 26, 2004, 01:49 PM
 
Originally posted by brandon420506:
I'm sorry, as I said, I'm pretty new at programming. I didn't really get what you were saying. I thought I did and I tried it but it didn't work. Do you think you could explain it a little easier, like step by step?
Ok, in Java, you have a class that you want to run when someone double-clicks a jar file. For this example, we'll assume that class is this very simple example (in a file called simpleApp.java):

Code:
import javax.swing.*; import java.awt.*; public class simpleApp extends JFrame { public simpleApp() { getContentPane().setLayout( new BorderLayout() ); JButton stopButton = new JButton( "Stop!" ); getContentPane().add( stopButton, BorderLayout.NORTH ); } public static void main( String[] args ) { simpleApp sa = new simpleApp(); sa.show(); } }
Ok, when we double-click the jar file, we want the main() method defined above to be executed. To accomplish this:

1) Compile the file: javac simpleApp.java
2) Create a new text file using TextEdit named MANIFEST.MF with the following content in the same folder as simpleApp.java and simpleApp.class:

Code:
Manifest-Version: 1.0 Main-Class: simpleApp
3) In a Terminal, cd into the same folder containing the files above.
4) In the same Terminal, do the following command:

Code:
jar -cfm myApp.jar MANIFEST.MF simpleApp.class
If you do that, it will create myApp.jar, which you can double-click in the Finder to launch your app.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Nodnarb  (op)
Mac Elite
Join Date: Jun 2004
Status: Offline
Reply With Quote
Jul 26, 2004, 09:38 PM
 
I tried it with my app first, and I got an error message that said "The jar file "myApp.jar" couldn't be launched. Check the Console for possible error messages."
Then I tried it with that simpleApp and I got the same error message.
Any suggestions?
Brandon
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 27, 2004, 04:42 PM
 
Originally posted by brandon420506:
I tried it with my app first, and I got an error message that said "The jar file "myApp.jar" couldn't be launched. Check the Console for possible error messages."
Then I tried it with that simpleApp and I got the same error message.
Any suggestions?
Brandon
I suspect that you failed to follow one of the steps.

In the Terminal type "java -jar myApp.jar" and see what the output is.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Nodnarb  (op)
Mac Elite
Join Date: Jun 2004
Status: Offline
Reply With Quote
Jul 28, 2004, 11:35 AM
 
I double checked and it seems I did every step correctly. I typed that into the terminal and the message I got was "Failed to load Main-Class manifest attribute from
myApp.jar". I got the same message when I did it with your simpleApp and with my app. I don't know what the reason could be.
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 28, 2004, 04:58 PM
 
Originally posted by brandon420506:
I double checked and it seems I did every step correctly. I typed that into the terminal and the message I got was "Failed to load Main-Class manifest attribute from
myApp.jar". I got the same message when I did it with your simpleApp and with my app. I don't know what the reason could be.
That means your manifest is either incorrect or was not included in the file. Make sure it is a plain text file with the exact content that I specified above. Do NOT copy and paste it, because Safari is unicode and you'll end up with 2-byte characters in the file. Type it in manually.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Nodnarb  (op)
Mac Elite
Join Date: Jun 2004
Status: Offline
Reply With Quote
Jul 28, 2004, 10:34 PM
 
I did copy and paste it the first time, and I was hoping that was why it didn't work. I typed it in textedit and made sure everything was correct. I still got the same error message for my app and the simpleApp. I don't know whats going on, but I'll try to figure it out. Thanks for trying to help.
Brandon
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 29, 2004, 09:30 AM
 
Originally posted by brandon420506:
I did copy and paste it the first time, and I was hoping that was why it didn't work. I typed it in textedit and made sure everything was correct. I still got the same error message for my app and the simpleApp. I don't know whats going on, but I'll try to figure it out. Thanks for trying to help.
Brandon
If you want to post your jar file somewhere I'll take a look at it.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Nodnarb  (op)
Mac Elite
Join Date: Jun 2004
Status: Offline
Reply With Quote
Jul 30, 2004, 12:04 AM
 
Do you mean the actual code for the program? If so, email me at brandon420506atmacdotcom and I'll send you the file as an attachment.
Thanks
Brandon
     
Nodnarb  (op)
Mac Elite
Join Date: Jun 2004
Status: Offline
Reply With Quote
Aug 1, 2004, 01:10 AM
 
I got it! I found an awesome app, called JJ edit, and it did it for me. It's a java IDE and it works very well, all I had to do was press "create jar" and it was done.
Anyone working with java should check out that program! (It's free!)
     
Registered User
Join Date: Oct 2003
Status: Offline
Reply With Quote
Aug 1, 2004, 07:17 PM
 
Brandon,

In the long run, you'll want to be able to create jar files by-hand as Arkham_c described, rather than rely on a GUI tool to do it for you. It's actually very simple, and will be worth the effort for you to figure out.

'jar' is a tool mostly like zip. It zips up your .class file(s) into an archive file (called something.jar). The command works very similar to the unix 'tar' command.

When jar creates this archive file (which you name (anything_you_want.jar) on the command line) it also creates a directory called META-INF (inside the jar file's zipped up directory structure) and places a file called MANIFEST.MF in there for you. Your job is to update that MANIFEST.MF file (which is just plain text) so the jar file is double-clickable. The update consists of simply adding one line to the file (and I put a newline at the end of it).

Contrary to Arkham_c's instructions, I like to let 'jar' create the file for me, then: extract it out of the jar file, edit it by adding the "Main-Class: Foo" line, and jam it back into the jar file (yeah, that way probably makes a little extra work for myself, but it works fine).

What follows are my brief reminder notes (that I peek at when I need to) on how to do it:

Code:
The simplest way to deploy an application is to distribute it as a JAR file. If you do choose to deploy your application from a JAR file in Mac OS X, the manifest file must specify which class contains the main method. Without this, the JAR file is not double-clickable. Use the jar command. It works like tar. jar cvf MyApp.jar Foo.class Bar.class // Manifest gets added automatically. // Have a look to see for yourself. [...]$ jar tf SomeJar.jar META-INF/ META-INF/MANIFEST.MF Foo.class Bar.class // Just extract the manifest: jar xf MyApp.jar META-INF/MANIFEST.MF vim META-INF/MANIFEST.MF // Add a "Main-Class: Foo" line to the end, then update the jar file: jar ufm MyApp.jar META-INF/MANIFEST.MF // Now, when you later update your source, update the jar file like so: javac Foo.java jar uf Foo.jar Foo.class // You can run it either by double-clicking it, or else // by doing: java -jar MyApp.jar When apps run by double-clicking them, they have std out sent to the Console.app.
See 'man jar' for more details.
     
Registered User
Join Date: Oct 2003
Status: Offline
Reply With Quote
Aug 1, 2004, 07:23 PM
 
Ah, one extra note. My instructions assume that your .class files are both in the default top-level unnamed package (i.e. that there's no package statement at the top of your .java files). If you have your files in some package, there may be some subdirectories you need to create to put your class files into before creating the jar file -- dunno. I haven't fiddled with jar files for a while...
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:05 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2