Packaging .dmg files for Mac OS X

I ported my Java game to Mac OS X (10.4+) and created a .dmg file for it. I even figured out how to compress it (though the compression rate was lousy). The file is available here.

This file works. It mounts the drive, and you can then double click on the Jar file to run the program.

However, this is not what I want. I want double clicking on the .dmg file to open up a window that lets you copy the whole application into the Applications folder. Some applications do this, though others don’t. How do I make this happen?

It may be that this has nothing to do with .dmg files in and of themselves. I’m a Newless Cluebie when it comes to Macs, so I’m not sure.

Ok, I figured out that I need to create a .app bundle. I’ve looked at a variety of urls and was baffled. Then, I tried exporting a .app bundle with Eclipse, but that didn’t quite seem to work. Finally, I downloaded a Jar Builder task for Ant and used that. All it did was copy the files to the directory, not do anything for the bundling itself.

This should be easy. This should be practically automatic. What’s going on here?

I have Tiger and don’t have XCode. The current version of XCode requires Leopard, so I can’t download it. So I haven’t tried the Jar Builder application.

Is there a simple way to create a .app bundle? I seem to be royally screwing it up.

Is there some alternative to creating a .app bundle?

I’ve never done it myself, but I know that Processing (http://www.processing.org) exports Mac (and PC and Linux) applications that you can run with a double click, and it doesn’t rely on XCode or anything like that. It’s all open source, so it should be fairly easy to figure out what’s going on.

Taking a browse through the source, it appears that you’d most likely be interested in the function “public boolean exportApplication(int exportPlatform)” in the file at http://dev.processing.org/source/index.cgi/trunk/processing/app/src/processing/app/Sketch.java?view=markup (search through it for that text). It looks like there’s a skeleton application that it starts from, so you might have to track that down and download it. I’m not sure if any of what it does is Processing specific…

To me, though, it looks like the most likely thing you’ve missed is that you need to set your myApp.app directory to be executable (“chmod +x myApp.app”) - even though the terminal won’t let you execute it directly, Finder knows to call “open myApp.app” when you double click it (which will work in the terminal, but only if it’s marked executable, otherwise you get a cryptic error). Try setting that, see if it does the trick.

Finally, I downloaded a Jar Builder task for Ant and used that.

You mean JarBundler, right?

Yes.

And I figured out how I was screwing things up with JarBundler. I saved a file to the wrong spot.

That was it.

Though my build file doesn’t quite work right now, I’m confident that I should be able to figure it out. I will work on it on Monday.

I was considering getting a Mac OS X 10.4 CD just so that I could get an old version of XCode (since I believe that’s where it comes from).

If I fail to get JarBundler to work, I will look into Processing. Somehow, I expect that it would be more complicated to figure out than I would like, but that’s only because I thought figuring out how to package Mac applications would take only a half hour or so.