diff --git a/README.md b/README.md index 1659eaba..f9618a1e 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Add the following `plugin` tag to your `pom.xml`. fvarrui.maven javapackager - 0.7.0 + 0.8.0 package @@ -42,6 +42,8 @@ Add the following `plugin` tag to your `pom.xml`. folder path ... + true|false + [...] @@ -50,15 +52,23 @@ Add the following `plugin` tag to your `pom.xml`. Where: -| Property | Mandatory | Default value | Description | -| ----------------------- | --------- | ------------- | ----------------------------------------------------------- | -| `mainClass` | Yes | `null` | Full path to your app main class. | -| `bundleJre` | No | `false` | Embed a customized JRE with the app. | -| `forceJreOptimization` | No | `false` | If JDK version < 13, it will try to reduce the bundled JRE. | -| `administratorRequired` | No | `false` | If true, app will run with administrator privileges. | -| `additionalResources` | No | [] | Additional files and folders to include in the bundled app. | - -Some assets, like app icons, must be located in: +| Property | Mandatory | Default value | Description | +| ----------------------- | --------- | ------------------------------ | ----------------------------------------------------------- | +| `mainClass` | Yes | `null` | Full path to your app main class. | +| `bundleJre` | No | `false` | Embed a customized JRE with the app. | +| `forceJreOptimization` | No | `false` | If JDK version < 13, it will try to reduce the bundled JRE. | +| `administratorRequired` | No | `false` | If true, app will run with administrator privileges. | +| `additionalResources` | No | [] | Additional files and folders to include in the bundled app. | +| `generateInstaller` | No | `true` | Generate an installer for the app. | +| `displayName` | No | `${project.name}` | App name to show. | +| `iconFile` | No | `null` | Path to the app icon file (PNG, ICO or ICNS). | +| `licenseFile` | No | `${project.licenses[0].url}` | Path to project license file. | +| `url` | No | `null` | App website URL. | +| `organizationName` | No | `${project.organization.name}` | Organization name. | +| `organizationUrl` | No | `${project.organization.url}` | Organization website URL. | +| `organizationEmail` | No | `null` | Organization email. | + +Some assets, such as application icons, could be located in `assets` folder organized by platform, and so it would not be necessary to specify the `iconFile` property: ``` @@ -68,12 +78,14 @@ Some assets, like app icons, must be located in: ├── macosx │   └── projectname.icns # on Mac OS X it has to be a icns file └── windows - └── projectname.ico # on Windows it has to be a ico file + └── projectname.ico # on Windows it has to be an ico file ``` -> Where **projectname** corresponds to `name` property in `pom.xml`. +Where **projectname** corresponds to `name` property in `pom.xml`. -> :warning: If icon is not specified, it will use a default icon for every platform. +> :warning: If `iconFile` property is not specified and it can't find the correct icon in `assets` folder, it will use next icon by default for all platforms: +> +> ![Default icon](https://raw.githubusercontent.com/fvarrui/JavaPackager/master/src/main/resources/linux/default-icon.png) Execute next command in project's root folder: @@ -83,11 +95,12 @@ mvn package By default, it will generate next artifacts in `target ` folder: -- A native application in `app` directory with a bundled JRE. -- A `projectname_projectversion.deb` package file on GNU/Linux. -- A `projectname_projectversion.rpm` package file on GNU/Linux (requires alien && rpmbuild). -- A `projectname_projectversion.exe` installer file on Windows. -- A `projectname_projectversion.dmg` installer file on Mac OS X. +- `app`: directory with the native application. +- `projectname-projectversion-runnable.jar`: runnable JAR file. +- `projectname_projectversion.deb`: DEB package file only on GNU/Linux. +- `projectname_projectversion.rpm`: RPM package file only on GNU/Linux (requires alien && rpmbuild). +- `projectname_projectversion.exe`: installer file only on Windows. +- `projectname_projectversion.dmg`: disk image file only on Mac OS X. ## Contributors diff --git a/pom.xml b/pom.xml index 11146acd..1f284a54 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ fvarrui.maven javapackager - 0.7.0 + 0.8.0 maven-plugin JavaPackager Maven Plugin diff --git a/src/main/java/fvarrui/maven/plugin/javapackager/PackageMojo.java b/src/main/java/fvarrui/maven/plugin/javapackager/PackageMojo.java index 66f9fa4b..7d49cc1d 100644 --- a/src/main/java/fvarrui/maven/plugin/javapackager/PackageMojo.java +++ b/src/main/java/fvarrui/maven/plugin/javapackager/PackageMojo.java @@ -63,6 +63,7 @@ public class PackageMojo extends AbstractMojo { private File appFolder; private File assetsFolder; private File jarFile; + private File executable; // plugin configuration properties @Parameter(defaultValue = "${project.build.directory}", property = "outputDir", required = true) @@ -71,15 +72,15 @@ public class PackageMojo extends AbstractMojo { @Parameter(property = "licenseFile", required = false) private File licenseFile; - @Parameter(defaultValue = "${project.build.directory}/app/${project.name}", property = "executable", required = true) - private File executable; - @Parameter(property = "iconFile") private File iconFile; @Parameter(defaultValue = "${java.version}", property = "jreMinVersion", required = true) private String jreMinVersion; + @Parameter(defaultValue = "true", property = "generateInstaller", required = true) + private Boolean generateInstaller; + @Parameter(property = "mainClass", required = true) private String mainClass; @@ -125,7 +126,7 @@ public PackageMojo() { } public void execute() throws MojoExecutionException { - + appFolder = new File(outputDirectory, "app"); if (!appFolder.exists()) { appFolder.mkdirs(); @@ -136,6 +137,8 @@ public void execute() throws MojoExecutionException { assetsFolder.mkdirs(); } + executable = new File(appFolder, name); + // if default license file doesn't exist and there's a license specified in // pom.xml file, get this last one if (licenseFile != null && !licenseFile.exists()) { @@ -163,7 +166,8 @@ public void execute() throws MojoExecutionException { FileUtils.copyResourceToFile("/mac/default-icon.icns", iconFile); } - createMacAppBundle(); + createMacApp(); + generateDmgImage(); } else if (SystemUtils.IS_OS_LINUX) { @@ -251,6 +255,8 @@ private Map getInfo() throws MojoExecutionException { } private void generateRpmPackage() throws MojoExecutionException { + if (!generateInstaller) return; + getLog().info("Generating RPM package..."); if (!debFile.exists()) { @@ -284,7 +290,7 @@ private void generateRpmPackage() throws MojoExecutionException { } - private void createMacAppBundle() throws MojoExecutionException { + private void createMacApp() throws MojoExecutionException { getLog().info("Creating Mac OS X app bundle..."); // create and set up directories @@ -342,16 +348,6 @@ private void createMacAppBundle() throws MojoExecutionException { // codesign app folder ProcessUtils.execute("codesign", "--force", "--deep", "--sign", "-", appFile); - // create a symlink to Applications folder - File targetFolder = new File("/Applications"); - File linkFile = new File(appFolder, "Applications"); - FileUtils.createSymlink(linkFile, targetFolder); - - // create the DMG file including app folder content - getLog().info("Generating the Disk Image file"); - File diskImageFile = new File(outputDirectory, name + "_" + version + ".dmg"); - ProcessUtils.execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", name, diskImageFile); - getLog().info("App Bundle generation finished"); } @@ -455,6 +451,8 @@ private void createWindowsExecutable() throws MojoExecutionException { } private void generateWindowsInstaller() throws MojoExecutionException { + if (!generateInstaller) return; + getLog().info("Generating Windows installer..."); // copy ico file to assets folder @@ -469,6 +467,8 @@ private void generateWindowsInstaller() throws MojoExecutionException { } private void generateDebPackage() throws MojoExecutionException { + if (!generateInstaller) return; + getLog().info("Generating DEB package ..."); // generate desktop file from velocity template @@ -547,6 +547,22 @@ private void generateDebPackage() throws MojoExecutionException { ), env); } + + private void generateDmgImage() throws MojoExecutionException { + if (!generateInstaller) return; + + getLog().info("Generating DMG disk image file"); + + // create a symlink to Applications folder + File targetFolder = new File("/Applications"); + File linkFile = new File(appFolder, "Applications"); + FileUtils.createSymlink(linkFile, targetFolder); + + // create the DMG file including app folder content + getLog().info("Generating the Disk Image file"); + File diskImageFile = new File(outputDirectory, name + "_" + version + ".dmg"); + ProcessUtils.execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", name, diskImageFile); + } private void copyAllDependencies(File libsFolder) throws MojoExecutionException { getLog().info("Copying all dependencies to app folder ...");