4

I would like to create a DMG file from Java.

The reason why it needs to be Java is twofold: It must be part of our build farm (which currently runs on a non Mac OS X platform) and our build uses Maven (which pretty much means Java).

As far as I can a tell inside a DMG file can be an ISO9660 file system. I can create such beast using this but then I still need the part where the whole thing is wrapped in the DMG format. Something like iso2dmg tool except I need it for Java.

When answering: Forget about the Maven part. If you have a Java solution then I can figure out the Maven stuff myself. (e.g. creating my own little Maven plugin if I need to).

Community
  • 1
  • 1
peterh
  • 18,404
  • 12
  • 87
  • 115
  • 1
    Not enough for an answer, but have you tried any of the installer libraries out there (that is, they package your app in installer form)? I would imagine at least some of them have that option. – Alvin Thompson Jun 14 '15 at 11:13
  • @AlvinThompson. Yeah. I have. These tools typically require you to execute on Mac OS X and their integration with build tools like Maven is poor. Lastly they are costly ... if all you want is to create a DMG file. – peterh Jun 14 '15 at 11:32

2 Answers2

2

You can use the javapackager tool.

A simple, well explained, step by step tutorial on how to create a DMG from java is here: http://centerkey.com/mac/java/

Marco
  • 423
  • 5
  • 7
  • 2
    Yeah, well, but the javapackager tool from Oracle is tied to the Mac OS X platform. You need to be **on** a Mac to produce the DMG. (which defeats the purpose of a build farm). There seems to be something in the DMG format which makes it impossible to create outside of a Mac, i.e. cannot be done from Java (without calling a native platform lib at least). – peterh May 26 '16 at 03:41
  • @peterh It isn't impossible (several [non-java approaches](http://stackoverflow.com/questions/286419/how-to-build-a-dmg-mac-os-x-file-on-a-non-mac-platform) exists) but knowing Apple's greedy "business strategies" I'm guessing it's a licensing issue. They want to "control" (aka make money out of) anything being created for their platforms, it's the same story with development of iOS applications (not to mention that running an OS X VM requires the host to be of Apple hardware). – Nadar Nov 11 '16 at 18:50
2

The appbundle-maven-plugin works on both Linux and Mac to generate an app bundle(YourProgram.app) and then a .dmg. Make sure you have genisoimage as that's what it uses in Linux to create the dmg.

<plugin>
    <groupId>sh.tak.appbundler</groupId>
    <artifactId>appbundle-maven-plugin</artifactId>
    <version>1.2.0</version>
</plugin>

https://github.com/federkasten/appbundle-maven-plugin