Skip to content

Commit 5f7f642

Browse files
committed
v0.8.8
1 parent a4490e4 commit 5f7f642

File tree

9 files changed

+113
-75
lines changed

9 files changed

+113
-75
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# JavaPackager
2-
JavaPackager Maven Plugin provides an easy way to package Java applications in native Windows, Mac OS X, or Linux executables.
2+
JavaPackager is a Maven plugin which provides an easy way to package Java applications in native Windows, Mac OS X, or GNU/Linux executables, and generates installers for them.
33

44
## How to use the plugin
55

@@ -60,7 +60,7 @@ Execute next command in project's root folder:
6060
mvn package
6161
```
6262

63-
By default, it generates next artifacts in `target ` folder:
63+
And by default it will generate next artifacts in `target ` folder:
6464

6565
| Artifact | Description |
6666
| ----------------------------------------- | ------------------------------------------------------------ |
@@ -77,24 +77,27 @@ By default, it generates next artifacts in `target ` folder:
7777

7878
| Property | Mandatory | Default value | Description |
7979
| ----------------------- | --------- | ------------------------------ | ------------------------------------------------------------ |
80-
| `mainClass` | Yes | `null` | Full path to your app main class. |
81-
| `bundleJre` | No | `false` | Embeds a customized JRE with the app. |
82-
| `customizedJre` | No | `true` | If `true`, a customized JRE will be generated, including only needed modules. Otherwise, all modules will be included. |
83-
| `jrePath` | No | `""` | Path to JRE folder. If specified, it will bundle this JRE with the app, and won't generate a customized JRE. For Java 8 version or least. |
84-
| `modules` | No | [] | Uses specified modules to customize the bundled JRE. Don't use `jdeps` to get module dependencies. |
8580
| `additionalModules` | No | [] | Adds additional modules other than the ones identified by `jdeps` before calling `jlink`. |
86-
| `administratorRequired` | No | `false` | If `true`, app will run with administrator privileges. |
8781
| `additionalResources` | No | [] | Additional files and folders to include in the bundled app. |
88-
| `platform` | No | `auto` | Specifies the target platform, which could be different to current one. Possible values: `auto`, `mac`, `linux`, `windows`. Use `auto` for using current platform as target. |
89-
| `generateInstaller` | No | `true` | Generates an installer for the app. |
82+
| `administratorRequired` | No | `false` | If `true`, app will run with administrator privileges. |
83+
| `bundleJre` | No | `false` | Embeds a customized JRE with the app. |
84+
| `copyDependencies` | No | `true` | If `true`, all dependencies (JAR files) will be bundled with the app. |
85+
| `customizedJre` | No | `true` | If `true`, a customized JRE will be generated, including only needed modules. Otherwise, all modules will be included. |
9086
| `displayName` | No | `${project.name}` | App name to show. |
87+
| `envPath` | No | `null` | Defines environment variable PATH in GNU/Linux and Mac OS X startup scripts. |
88+
| `generateInstaller` | No | `true` | Generates an installer for the app. |
9189
| `iconFile` | No | `null` | Path to the app icon file (PNG, ICO or ICNS). |
90+
| `jrePath` | No | `""` | Path to JRE folder. If specified, it will bundle this JRE with the app, and won't generate a customized JRE. For Java 8 version or least. |
9291
| `licenseFile` | No | `${project.licenses[0].url}` | Path to project license file. |
93-
| `url` | No | `null` | App website URL. |
92+
| `mainClass` | Yes | `null` | Full path to your app main class. |
93+
| `modules` | No | [] | Uses specified modules to customize the bundled JRE. Don't use `jdeps` to get module dependencies. |
9494
| `organizationName` | No | `${project.organization.name}` | Organization name. |
9595
| `organizationUrl` | No | `${project.organization.url}` | Organization website URL. |
9696
| `organizationEmail` | No | `null` | Organization email. |
97-
| `envPath` | No | `null` | Defines environment variable PATH in GNU/Linux and Mac OS X startup scripts. |
97+
| `platform` | No | `auto` | Specifies the target platform, which could be different to current one. Possible values: `auto`, `mac`, `linux`, `windows`. Use `auto` for using current platform as target. |
98+
| `runnableJar` | No | `null` | Specifies your own JAR file to be bundled. If it's ommited, the plugin packages your code in a runnable JAR and bundle with the app. |
99+
| `url` | No | `null` | App website URL. |
100+
| `vmArgs` | No | [] | Adds VM arguments. |
98101

99102
> See [**Older documentation**](#Older documentation) for previous versions properties.
100103
@@ -119,8 +122,6 @@ Some assets, such as application icons, could be located in `assets` folder orga
119122
>
120123
> ![Default icon](https://raw.githubusercontent.com/fvarrui/JavaPackager/master/src/main/resources/linux/default-icon.png)
121124
122-
>
123-
124125
## How to build and install the plugin
125126

126127
Execute next commands in BASH (GNU/Linux or macOS) or CMD (Windows):

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
<maven.compiler.source>1.8</maven.compiler.source>
1818
<maven.compiler.target>1.8</maven.compiler.target>
19-
<exec.mainClass>fvarrui.maven.plugin.javapackager.Main</exec.mainClass>
2019
</properties>
2120

2221
<dependencies>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
2-
#Wed Jan 15 16:36:58 WET 2020
2+
#Thu Jan 16 12:38:57 WET 2020
33
javapackager-0.8.8.jar>=
44
javapackager-0.8.8.pom>=
1.33 KB
Binary file not shown.

releases/fvarrui/maven/javapackager/0.8.8/javapackager-0.8.8.pom

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
<maven.compiler.source>1.8</maven.compiler.source>
1818
<maven.compiler.target>1.8</maven.compiler.target>
19-
<exec.mainClass>fvarrui.maven.plugin.javapackager.Main</exec.mainClass>
2019
</properties>
2120

2221
<dependencies>

releases/fvarrui/maven/javapackager/maven-metadata-local.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<version>0.8.7</version>
2020
<version>0.8.8</version>
2121
</versions>
22-
<lastUpdated>20200115163658</lastUpdated>
22+
<lastUpdated>20200116123857</lastUpdated>
2323
</versioning>
2424
</metadata>

src/main/java/fvarrui/maven/plugin/javapackager/PackageMojo.java

Lines changed: 88 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class PackageMojo extends AbstractMojo {
6969

7070
// plugin configuration properties
7171

72-
@Parameter(defaultValue = "${project.build.directory}", property = "outputDir", required = true)
72+
@Parameter(defaultValue = "${project.build.directory}", property = "outputDirectory", required = true)
7373
private File outputDirectory;
7474

7575
@Parameter(property = "licenseFile", required = false)
@@ -78,9 +78,6 @@ public class PackageMojo extends AbstractMojo {
7878
@Parameter(property = "iconFile")
7979
private File iconFile;
8080

81-
@Parameter(defaultValue = "${java.version}", property = "jreMinVersion", required = true)
82-
private String jreMinVersion;
83-
8481
@Parameter(defaultValue = "true", property = "generateInstaller", required = true)
8582
private Boolean generateInstaller;
8683

@@ -132,11 +129,41 @@ public class PackageMojo extends AbstractMojo {
132129
@Parameter(property = "additionalModules", required = false)
133130
private List<String> additionalModules;
134131

132+
/**
133+
* Which platform to build, one of:
134+
* <ul>
135+
* <li><tt>auto</tt> - automatically detect based on the host OS (the default)</li>
136+
* <li><tt>mac</tt></li>
137+
* <li><tt>linux</tt></li>
138+
* <li><tt>windows</tt></li>
139+
* </ul>
140+
* To build for multiple platforms at once, add multiple executions to the plugin's configuration.
141+
*/
135142
@Parameter(defaultValue = "auto", property = "platform", required = true)
136143
private Platform platform;
144+
145+
@Parameter(property = "envPath", required = false)
146+
private String envPath;
147+
148+
/**
149+
* Additional arguments to provide to the JVM (for example <tt>-Xmx2G</tt>).
150+
*/
151+
@Parameter(property = "vmArgs", required = false)
152+
private List<String> vmArgs;
137153

138-
@Parameter(property = "path", required = false)
139-
private String path;
154+
/**
155+
* Provide your own runnable .jar (for example, a shaded .jar) instead of letting this plugin create one via
156+
* the <tt>maven-jar-plugin</tt>.
157+
*/
158+
@Parameter(property = "runnableJar", required = false)
159+
private String runnableJar;
160+
161+
/**
162+
* Whether or not to copy dependencies into the bundle. Generally, you will only disable this if you specified
163+
* a <tt>runnableJar</tt> with all dependencies shaded into the .jar itself.
164+
*/
165+
@Parameter(defaultValue = "true", property = "copyDependencies", required = true)
166+
private Boolean copyDependencies;
140167

141168
public PackageMojo() {
142169
super();
@@ -155,7 +182,13 @@ public void execute() throws MojoExecutionException {
155182
if (platform == null || platform == Platform.auto) {
156183
platform = currentPlatform;
157184
}
185+
158186
getLog().info("Packaging app for " + platform);
187+
188+
// creates output directory if
189+
if (!outputDirectory.exists()) {
190+
outputDirectory.mkdirs();
191+
}
159192

160193
// creates app destination folder
161194
appFolder = new File(outputDirectory, "app");
@@ -172,20 +205,17 @@ public void execute() throws MojoExecutionException {
172205
// sets app's main executable file
173206
executable = new File(appFolder, name);
174207

175-
// if default license file doesn't exist and there's a license specified in
176-
// pom.xml file, gets this last one
177-
if (licenseFile != null && !licenseFile.exists()) {
178-
getLog().warn("Specified license file doesn't exist: " + licenseFile.getAbsolutePath());
179-
licenseFile = null;
180-
}
181-
// if license not specified, gets from pom
182-
if (licenseFile == null && !mavenProject.getLicenses().isEmpty()) {
183-
licenseFile = new File(mavenProject.getLicenses().get(0).getUrl());
184-
}
208+
// locates license file
209+
resolveLicense();
185210

186211
// creates a runnable jar file
187-
createRunnableJar();
188-
212+
if (runnableJar == null || runnableJar.isBlank()) {
213+
createRunnableJar();
214+
} else {
215+
getLog().info("Using runnable JAR: " + runnableJar);
216+
jarFile = new File(runnableJar);
217+
}
218+
189219
// collects app info
190220
this.info = getInfo();
191221

@@ -206,8 +236,24 @@ public void execute() throws MojoExecutionException {
206236
break;
207237
default:
208238
throw new MojoExecutionException("Unsupported operating system: " + SystemUtils.OS_NAME + " " + SystemUtils.OS_VERSION + " " + SystemUtils.OS_ARCH);
209-
}
239+
}
240+
241+
}
210242

243+
/**
244+
* Locates license file
245+
*/
246+
private void resolveLicense() {
247+
// if default license file doesn't exist and there's a license specified in
248+
// pom.xml file, gets this last one
249+
if (licenseFile != null && !licenseFile.exists()) {
250+
getLog().warn("Specified license file doesn't exist: " + licenseFile.getAbsolutePath());
251+
licenseFile = null;
252+
}
253+
// if license not specified, gets from pom
254+
if (licenseFile == null && !mavenProject.getLicenses().isEmpty()) {
255+
licenseFile = new File(mavenProject.getLicenses().get(0).getUrl());
256+
}
211257
}
212258

213259
/**
@@ -263,14 +309,13 @@ private void createRunnableJar() throws MojoExecutionException {
263309
}
264310

265311
/**
266-
* Collects info needed for Velocity templates
312+
* Collects info needed for Velocity templates and populates a map with it
267313
*
268314
* @return Map with collected properties
269315
* @throws MojoExecutionException
270316
*/
271-
private Map<String, Object> getInfo() throws MojoExecutionException {
317+
private Map<String, Object> getInfo() {
272318
HashMap<String, Object> info = new HashMap<>();
273-
274319
info.put("name", name);
275320
info.put("displayName", displayName);
276321
info.put("version", version);
@@ -284,8 +329,8 @@ private Map<String, Object> getInfo() throws MojoExecutionException {
284329
info.put("mainClass", mainClass);
285330
info.put("jarFile", jarFile.getName());
286331
info.put("license", licenseFile != null ? licenseFile.getAbsolutePath() : "");
287-
info.put("path", path);
288-
332+
info.put("envPath", envPath);
333+
info.put("vmArgs", StringUtils.join(vmArgs, " "));
289334
return info;
290335
}
291336

@@ -467,37 +512,30 @@ private void createWindowsApp() throws MojoExecutionException {
467512

468513
// prepares launch4j plugin configuration
469514

470-
List<Element> config = new ArrayList<>();
515+
List<Element> jreElements = new ArrayList<>();
516+
jreElements.add(element("path", bundleJre ? "jre" : "%JAVA_HOME%"));
517+
jreElements.addAll(vmArgs.stream().map(a -> element("opt", a)).collect(Collectors.toList()));
471518

519+
List<Element> config = new ArrayList<>();
472520
config.add(element("headerType", "gui"));
473521
config.add(element("jar", jarFile.getAbsolutePath()));
474522
config.add(element("outfile", executable.getAbsolutePath() + ".exe"));
475523
config.add(element("icon", iconFile.getAbsolutePath()));
476524
config.add(element("manifest", manifestFile.getAbsolutePath()));
477525
config.add(element("classPath", element("mainClass", mainClass)));
478-
479-
if (bundleJre) {
480-
config.add(
481-
element("jre", element("path", "jre")
482-
));
483-
} else {
484-
config.add(
485-
element("jre", element("path", "%JAVA_HOME%")
486-
));
487-
}
488-
489-
config.add(
490-
element("versionInfo",
491-
element("fileVersion", "1.0.0.0"),
492-
element("txtFileVersion", "1.0.0.0"),
493-
element("copyright", organizationName),
494-
element("fileDescription", description),
495-
element("productVersion", version + ".0"),
496-
element("txtProductVersion", version + ".0"),
497-
element("productName", name),
498-
element("internalName", name),
499-
element("originalFilename", name + ".exe")
500-
));
526+
config.add(element("jre", jreElements.toArray(new Element[jreElements.size()])));
527+
config.add(element("versionInfo",
528+
element("fileVersion", "1.0.0.0"),
529+
element("txtFileVersion", "1.0.0.0"),
530+
element("copyright", organizationName),
531+
element("fileDescription", description),
532+
element("productVersion", version + ".0"),
533+
element("txtProductVersion", version + ".0"),
534+
element("productName", name),
535+
element("internalName", name),
536+
element("originalFilename", name + ".exe")
537+
)
538+
);
501539

502540
// invokes launch4j plugin to generate windows executable
503541
executeMojo(
@@ -653,6 +691,8 @@ private void generateDmgImage() throws MojoExecutionException {
653691
* @throws MojoExecutionException
654692
*/
655693
private void copyAllDependencies(File libsFolder) throws MojoExecutionException {
694+
if (copyDependencies != null && !copyDependencies) return;
695+
656696
getLog().info("Copying all dependencies to app folder ...");
657697

658698
// invokes plugin to copy dependecies to app libs folder
@@ -759,7 +799,6 @@ private String getRequiredModules(File libsFolder) throws MojoExecutionException
759799

760800
File jdeps = new File(System.getProperty("java.home"), "/bin/jdeps");
761801

762-
// File [] jarLibs = libsFolder.listFiles(new FilenameExtensionFilter("jar"));
763802
File jarLibs = new File(libsFolder, "*.jar");
764803

765804
List<String> modulesList;

src/main/resources/linux/startup.sh.vtl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ JAVA=$SCRIPTPATH/jre/bin/java
77
JAVA=java
88
#end
99
BINARY=$SCRIPTPATH/${info.name}
10-
#if($info.path)
11-
export PATH=${info.path}
10+
#if($info.envPath)
11+
export PATH=${info.envPath}
1212
#end
1313
#if($info.administratorRequired)
14-
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY GDKBACKEND=x11 $JAVA -jar $BINARY $@
14+
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY GDKBACKEND=x11 $JAVA ${info.vmArgs} -jar $BINARY $@
1515
#else
16-
$JAVA -jar $BINARY $@
16+
$JAVA ${info.vmArgs} -jar $BINARY $@
1717
#end
1818
exit 0

src/main/resources/mac/startup.vtl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ JAVA=$SCRIPTPATH/../PlugIns/jre/Contents/Home/bin/java
77
JAVA=`/usr/libexec/java_home`/bin/java
88
#end
99
BINARY=$SCRIPTPATH/../Resources/Java/${info.jarFile}
10-
#if($info.path)
11-
export PATH=${info.path}
10+
#if($info.envPath)
11+
export PATH=${info.envPath}
1212
#end
1313
#if($info.administratorRequired)
14-
/usr/bin/osascript -e "do shell script \"$JAVA -Dapple.laf.useScreenMenuBar=true -Xdock:name='${info.displayName}' -Xdock:icon=$SCRIPTPATH/../Resources/${info.name}.icns -jar $BINARY $@\" with administrator privileges"
14+
/usr/bin/osascript -e "do shell script \"$JAVA ${info.vmArgs} -Dapple.laf.useScreenMenuBar=true -Xdock:name='${info.displayName}' -Xdock:icon=$SCRIPTPATH/../Resources/${info.name}.icns -jar $BINARY $@\" with administrator privileges"
1515
#else
16-
$JAVA -Dapple.laf.useScreenMenuBar=true -Xdock:name="${info.displayName}" -Xdock:icon=$SCRIPTPATH/../Resources/${info.name}.icns -jar $BINARY $@
16+
$JAVA ${info.vmArgs} -Dapple.laf.useScreenMenuBar=true -Xdock:name="${info.displayName}" -Xdock:icon=$SCRIPTPATH/../Resources/${info.name}.icns -jar $BINARY $@
1717
#end

0 commit comments

Comments
 (0)