 |
 |
Jar Bundler
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2004
Status:
Offline
|
|
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
|
|
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
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2004
Status:
Offline
|
|
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
|
|
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
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2004
Status:
Offline
|
|
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
|
|
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
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2004
Status:
Offline
|
|
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
|
|
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
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2004
Status:
Offline
|
|
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
|
|
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
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2004
Status:
Offline
|
|
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
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2004
Status:
Offline
|
|
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
|
|
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
|
|
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...
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum 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
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|