Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Jar Bundler Problems

Hi, I'm learning Java and I have my own application. It works perfectly when I open the jarfile, but when I use Jar Bundler to convert it to an app, it quits before it opens. The icon appears in the Dock and then disappears. Also, when I try to choose "Main class" the file never appears after I choose it. Does anyone know how to fix this or any other alternatives? Thanks.

Posted on Apr 28, 2013 2:38 AM

Reply
59 replies

Jul 16, 2013 9:27 AM in response to Arc676

I'm puzzled by the fact that, at least once, you managed to create a working bundle (app).

What may be the difference between that one and the other attempts.


As I said, my attempt to create an app from a single class-jar failed, so I wonder what the difference is.


On Jul 10, I gave you a few links, one of them points at an alternative using the 'ant' program, found on every OSX.


I opened 2 programs I downloaded as .dmg, instaled into .app and I found that the file 'JavaApplicationStub' in the directory MacOS, under Contents, was different for those 2 programs.

I wonder why, as the only thing those must do is to start the JAVA runtime and set the icon.


That brings me to the idea that this 'stub' is a tiny C-program that you could write yourself.


;JOOP!

Jul 18, 2013 6:08 AM in response to Arc676

Hi,

first, do not over-estimate C, C++, C# or Obj-C: please write your applications in JAVA.

You will find out why.

Then, I can not see what's in that stub, but if it were a JAVA program it could be as small as:


public class Stub

{

public static void main() throws IOException

{

Runtime.getRuntime().exec

(

new String[] { "<where is the JAVA runtime", "-jar", "<where is my .jar>",

null,

null

);

}

}


May be there is some extra code to publish the icon, but that should be all.

Of course, when you packed multiple .jar's the commandline would be more complex.


By the way: although I wrote in C for 23 years, I avoid it where I can:

on OSX I write in JAVA, or call some shell command or I even write some shell script.

Clean and quick.


Now, this would be our last resort; let's:

1) find out why one of your bundles works,

2) try the 'ant' program published in one of the links I gave you.

;JOOP!

Jul 18, 2013 6:11 AM in response to Arc676

Because I'm very busy at the moment I found a very strange, temporary, solution:


In Finder, drag your .jar to the dock. Right click it and make it sit there permanently.

Now you can always start your .jar from the dock.

The only problems are: it has always the coffee-cup-icon.

And so does the running application, although the application name is displayed.

;JOOP!

Aug 1, 2013 9:08 AM in response to Arc676

I solved it! I got it running for several of my applications and I could even set one of them as "run at login".


The solution is found in:


http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.h tml


It works as follows:

1) you got your jar, thus ignore everything that still must create a .jar

2) create a directory to work in.

3) put your .jar in this directory.

4) download appbundler-1.0.jar and put it in subdirectory 'lib'.

5) create subdirectory 'output' for the app.

6) get 'ant' (although, it was already present and installed on my Mac from the start).

7) edit build.xml as this:


<?xml version="1.0" encoding="UTF-8"?>

<project name="MyProgram" default="default" basedir=".">


<taskdef name="bundleapp"

classname="com.oracle.appbundler.AppBundlerTask"

classpath="lib/appbundler-1.0.jar" />


<target name="MyProgram">

<bundleapp outputdirectory="output"

name="MyProgram"

displayname="MyProgram application"

identifier="MyProgram"

mainclassname="MyProgram">

<classpath file="MyProgram.jar" />

</bundleapp>

</target>

</project>


8) from the command line (in that directory): ant MyProgram

9) test it in Finder (click the app)


a) replace the default icon in the app under resources by your own .icns icon.

(must be square and the width must be a power of 2, preferred 512x512)

b) edit the info.plist inside the app to address the right icon.


NOTE: you will see in the plist, that the application requires JAVA 6.0,

that's only for deliveries to customers.

From here you can play games:

new icon? just put it there.

new version of your program? just replace the .jar (I did it already).

Success!

;JOOP!

Aug 2, 2013 5:52 AM in response to Arc676

A small correction on my last post:


the identifier field in the build.xml should have a system-unique value.

That means that you should put your name or such in front of the program name

to avoid conflicts with other programs on the system.

Thus something like:


identifier="Arc676.MyProgram"


Read all about it in:


https://java.net/downloads/appbundler/appbundler.html and

http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlis tKeyReference/Articles/CoreFoundationKeys.html


Good luck,

;JOOP!

Aug 3, 2013 8:28 AM in response to etresoft

"Obviously the Android folks saw Java's potential in that environment too."


A slew of the folk that worked on Java now work at G. Not surprising given Schmidt is there.


But a little historical note: Java, aka Oak, was designed as an embedded operating environment. Even now ObjC kind of is catching up with some of the basic elements designed into Java. The biggest problem for Java was Sun.


I cut my teeth on pre ANSI C and industrial applications.. I agree about C++, but Java is still one of the cleanest OO languages out there. All of your laments apply to any language. Apply Stugeon's law.

Aug 10, 2013 10:08 AM in response to Sciuriware

This is the content of build.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project name="SHORTNAME__OF_MY_APP" default="default" basedir=".">


<taskdef name="bundleapp"

classname="com.oracle.appbundler.AppBundlerTask"

classpath="lib/appbundler-1.0.jar" />


<target name="SHORTNAME_OF_MY_APP">

<bundleapp outputdirectory="output"

name="NAME_OF_MY_APP_DIFFERENT_FROM_ABOVE"

displayname="SHORTNAME_OF_MY_APP"

identifier="SHORTNAME_OF_MY_APP"

mainclassname="NAME_OF_MY_APP_ALSO_DIFFERENT">

<classpath file="SHORTNAME_OF_MY_APP.jar" />

</bundleapp>

</target>

</project>


The different variable names are to show that the text is different.

When I run "ant SHORTNAME_OF_MY_APP" in Terminal, the build is successful, but the app still quits on open.

Aug 10, 2013 12:52 PM in response to Arc676

You should check a few things:


I built several app's now, some from a very large and complex .jar

My last build.xml looks:


<?xml version="1.0" encoding="UTF-8"?>

<project name="MyApplication" default="default" basedir=".">


<taskdef name="bundleapp"

classname="com.oracle.appbundler.AppBundlerTask"

classpath="lib/appbundler-1.0.jar" />


<target name="MyApplication">

<bundleapp outputdirectory="Output"

name="MyApplication"

displayname="MyApplication"

identifier="xy.MyDomain.MyApplication"

icon="/PathToMyApplicationIcon/MyApplication.icns"

mainclassname="MyApplication">

<classpath file="/PatheToMyJarFile/MyApplication.jar" />

</bundleapp>

</target>

</project>


with 'MyApplication', 'xy.MyDomain' and those paths faked.


Now, assuming that you could run the .jar file by itself, check the contents of the produced app:

the .jar file is to be found in : Output/MyApplication.app/Contents/Java/

check that the .jar is the same; you could still run it from there the old way.

Now look in Output/MyApplication.app/Contents/MacOS/

there is 'JavaAppLauncher'.

If you double click that, the application must run, but with an extra terminal window.

If that doesnot work the app is faulty.


It's some time that we started all this, but at this moment I can create app's of all my JAVA programs

and run them, so there must be something weird about your .jar or app structure.

Even my 512x512 .icns icons show up in the dock.


;JOOP!

Sep 27, 2013 2:50 PM in response to Sciuriware

Hi,

I really haven't been working on this lately. I've been thinking about trying to download Xcode 3.1.3 because it has templates to create Java apps, but I don't know if the product of the project is an app or a jar file. I really appreciate the time you have dedicated to helping me in this matter, but it just doesn't seem to be working. If you have any other tips or software I would welcome anything, but these jar files just don't seem to export into apps. At this point I'm not even going to bother with keeping my app name and everything to myself because I have abandoned this project to work on more advanced applications. The exact content of build.xml is the following:


<?xml version="1.0" encoding="UTF-8"?>

<project name="HC12" default="default" basedir=".">


<taskdef name="bundleapp"

classname="com.oracle.appbundler.AppBundlerTask"

classpath="lib/appbundler-1.0.jar" />


<target name="HC12">

<bundleapp outputdirectory="output"

name="HumanCreator12"

displayname="HC12"

identifier="HC12"

mainclassname="HumanCreator">

<classpath file="HC12.jar" />

</bundleapp>

</target>

</project>


My app name is "HumanCreator" which is an app I made a long time ago. I later learned about the game "The Sims" and this game is basically the same thing. I don't have any intention of publishing it in any way not only because it isn't original but because this specific app has no graphics: it's just swing components, action listeners, and file i/o. If you don't feel like answering to this post anymore it's OK, because I am also getting a little tired of it. However, this app has evolved a lot and has been at the center of my programming experience up to now, so if you have anything else to suggest to make it work I will appreciate it.


The jar file and everything are in a folder, and Terminal's "ls -FR" command returns the following:


HC12.jar build.xml lib/ output/


./lib:

appbundler-1.0.jar


./output:


Thanks again


P.S. If you're interested, by "evolved" I mean that it has gone under a lot of work. It used to be an extension of acm.program.ConsoleProgram (I'm not sure if you're familiar with the package, it's very basic and mainly for applets). It later became a console app which was based on java.io.BufferedReader and the System.out.println(String) method to print and read output and input on the console. It has now become an app with a GUI, but it doesn't mean much since there are no graphics and it isn't a real app.

Jar Bundler Problems

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.