Here is the step-by-step that I did to do this with a test project on Ubuntu 16.04.1 LTS .
In your case, steps 1 through 3 will be executed on your GNU / Linux env and last on Mac OS X.
1. Download the JRE
Since you only need a JRE , the easiest way to do this is:
- To go to the download area ,
- Click
JRE DOWNLOAD , - Choose
tar.gz the JRE version for Mac OS X , which is currently jre-8u112-macosx-x64.tar.gz . - Disconnect the contents of the archive in the folder of your choice, which we will call
${jre-folder} (for example, /foo/bar/jre1.8.0_112.jre ).
2. Create your test project
My typical maven project structure:
Testproject
βββ src
| βββ main
| βββ java
| βββ my
| βββ pkg
| βββ MyClass.java
βββ pom.xml
My class is my.pkg.MyClass , which actually performs an arbitrary task. Here, it simply removes the system properties into a temporary file, just to be able to easily verify that it was called:
package my.pkg; import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; public class MyClass { public static void main(String[] args) throws IOException { Path path = Files.createTempFile("MyClass", "txt"); try (BufferedWriter writer = Files.newBufferedWriter(path)) { System.getProperties() .entrySet() .stream() .forEach( entry -> { try { writer.write(entry.getKey() + "=" + entry.getValue() + "\n"); } catch (IOException e) { throw new IllegalStateException(e); } } ); } } }
My pom file:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>TestProject</groupId> <artifactId>TestProject</artifactId> <version>0.1-SNAPSHOT</version> <packaging>jar</packaging> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>sh.tak.appbundler</groupId> <artifactId>appbundle-maven-plugin</artifactId> <version>1.1.0</version> <configuration> <mainClass>my.pkg.MyClass</mainClass> <jrePath>${jre-folder}</jrePath> <generateDiskImageFile>true</generateDiskImageFile> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>bundle</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
3. Create your test project
Just run the mvn package appbundle:bundle command from the root of the TestProject directory.
This will create a dmg file in the target folder with the JRE for Mac OS X included , in this specific case it will be called TestProject-0.1-SNAPSHOT.dmg .
4. Check the test project
On target Mac OS X :
- Double click the dmg file, it will automatically install the image,
- Then you can double-click
TestProject.app , you will see that the icon appears and disappears quickly, since the test program is quite short. - You can verify that it worked correctly by running
cat $TMPDIR/MyClass* from the terminal, you will see the contents of a temporary file created by the test application.
5. Add resources to the dmg file
To add resources to the generated dmg file, you can use additionalResources with fileSet .
<plugin> <groupId>sh.tak.appbundler</groupId> <artifactId>appbundle-maven-plugin</artifactId> <version>1.1.0</version> <configuration> ... <additionalResources> <fileSet> <directory>/path/to/my/resources/folder</directory> <includes> <include>*.pdf</include> </includes> </fileSet> </additionalResources> </configuration> ... </plugin>
In this example, all pdf files from /path/to/my/resources/folder will be added to the generated dmg file.
6. Add resources to the application file
To add resources to the generated application file , you can use additionalResources with fileSet .
<plugin> <groupId>sh.tak.appbundler</groupId> <artifactId>appbundle-maven-plugin</artifactId> <version>1.1.0</version> <configuration> ... <additionalBundledClasspathResources> <fileSet> <directory>/path/to/my/resources/folder</directory> <includes> <include>*.pdf</include> </includes> </fileSet> </additionalBundledClasspathResources> </configuration> ... </plugin>
In this example, all pdf files from /path/to/my/resources/folder will be added to the generated application file in /Contents/Java/lib , they will be automatically included in the class path of your application, so you can easily get them .