Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Commit 843d208

Browse files
committed
Refactored Java code.
- Replaced command line parser, now uses JewelCLI. - Extracted config & minimization code into separate modules. - Added more minimize options. Minimize profiles now use a JSON format to utilize these options. - Aligned command line & JSON parameter names. - Amended error checks & log output. - Added 'oraclejre8' minimization profile, following Oracle's rules for JRE redistribution. - Updated documentation.
1 parent 977b59c commit 843d208

14 files changed

+1135
-408
lines changed

AUTHORS

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Mario Zechner, badlogic, contact at badlogicgames dot com
1+
Mario Zechner, badlogic, contact at badlogicgames dot com
2+
Daniel Ludwig, code-disaster, codi at code-disaster dot com

README.md

+102-40
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,47 @@
11
# packr
22

3-
Packages your JAR, assets and a JVM for distribution on Windows, Linux and Mac OS X, adding a native executable file to make it appear like the app is a native app. Packr is most suitable for GUI applications, such as games made with [libGDX](http://libgdx.badlogicgames.com/).
3+
__Public Service Announcement: With packr v2.0, command line interfaces to both packr.jar and the native executable have changed, as well as the format of minimize profiles! If you upgrade from a previous version, please read this documentation again to make sure you've updated your configuration(s) accordingly.__
4+
5+
## About
6+
7+
Packages your JAR, assets and a JVM for distribution on Windows, Linux and Mac OS X, adding a native executable file to make it appear like a native app. Packr is most suitable for GUI applications, such as games made with [libGDX](http://libgdx.badlogicgames.com/).
48

59
#### [Download Packr](http://bit.ly/packrgdx)
610

711
## Usage
812

9-
You point packr at your JAR file (containing all your code and assets), a JSON config file (specifying parameters to the JVM and the main class) and a URL or local file location to an OpenJDK build for the platform you want to build. Invoking packr from the command line may look like this:
13+
You point packr at your JAR file(s) containing your code and assets, some configuration parameters, and a URL or local file location to a JDK build for your target platform.
14+
15+
Invoking packr from the command line may look like this:
1016

1117
```bash
1218
java -jar packr.jar \
13-
-platform mac \
14-
-jdk "openjdk-1.7.0-u45-unofficial-icedtea-2.4.3-macosx-x86_64-image.zip" \
15-
-executable myapp \
16-
-classpath myapp.jar \
17-
-mainclass "com.my.app.MainClass" \
18-
-vmargs "-Xmx1G" \
19-
-resources src/main/resources;path/to/other/assets \
20-
-minimizejre "soft" \
21-
-outdir out
19+
--platform mac \
20+
--jdk openjdk-1.7.0-u45-unofficial-icedtea-2.4.3-macosx-x86_64-image.zip \
21+
--executable myapp \
22+
--classpath myapp.jar \
23+
--mainclass com.my.app.MainClass \
24+
--vmargs Xmx1G \
25+
--resources src/main/resources path/to/other/assets \
26+
--minimizejre soft \
27+
--output out-mac
2228
```
2329

2430
| Parameter | Meaning |
2531
| --- | --- |
2632
| platform | one of "windows32", "windows64", "linux32", "linux64", "mac" |
27-
| jdk | ZIP file location or URL to an OpenJDK build containing a JRE. Prebuild JDKs can be found at https://github.com/alexkasko/openjdk-unofficial-builds |
33+
| jdk | ZIP file location or URL to an OpenJDK or Oracle JDK build containing a JRE. Prebuild OpenJDK packages can be found at https://github.com/alexkasko/openjdk-unofficial-builds |
2834
| executable | name of the native executable, without extension such as ".exe" |
35+
| classpath | file locations of the JAR files to package |
36+
| mainclass | the fully qualified name of the main class, using dots to delimit package names |
37+
| vmargs | list of arguments for the JVM, without leading dashes, e.g. "Xmx1G" |
38+
| resources (optional) | list of files and directories to be packaged next to the native executable |
39+
| minimizejre | minimize the JRE by removing directories and files as specified by an additional config file. Comes with a few config files out of the box. See below for details on the minimization config file. |
40+
| output | the output directory |
2941
| icon (optional, OS X) | location of an AppBundle icon resource (.icns file) |
30-
| classpath | file locations of the JAR files to package, separated by `;` |
3142
| bundleidentifier (optional, OS X) | the bundle identifier of your Java application, e.g. "com.my.app" |
32-
| mainclass | the fully qualified name of the main class, using dots to delimit package names |
33-
| vmargs | list of arguments for the JVM, separated by `;`, e.g. "-Xmx1G" |
34-
| outdir | output directory |
35-
| resources (optional) | list of files and directories to be packaged next to the native executable, separated by `;`.
36-
| minimizejre | minimize the JRE by removing directories and files as specified by the config file. Comes with two config files out of the box called "soft" and "hard". See below for details on the minimization config file. |
43+
| verbose | prints more status information during processing, which can be useful for debugging |
44+
| help | shows the command line interface help |
3745

3846
Alternatively, you can put all the command line arguments into a JSON file which might look like this:
3947

@@ -47,14 +55,14 @@ Alternatively, you can put all the command line arguments into a JSON file which
4755
],
4856
"mainclass": "com.my.app.MainClass",
4957
"vmargs": [
50-
"-Xmx1G"
58+
"Xmx1G"
5159
],
5260
"resources": [
5361
"src/main/resources",
5462
"path/to/other/assets"
5563
],
5664
"minimizejre": "soft",
57-
"outdir": "out-mac"
65+
"output": "out-mac"
5866
}
5967
```
6068

@@ -64,7 +72,15 @@ You can then invoke the tool like this:
6472
java -jar packr.jar my-packr-config.json
6573
```
6674

67-
Finally, you can use packr from within your code. Just add the JAR file to your project, either manually, or via the following Maven dependency:
75+
It is possible to combine a JSON configuration and the command line. For single options, the command line parameter overrides the equivalent JSON option. For multi-options (e.g. `classpath` or `vmargs`), the options are merged.
76+
77+
This is an example which overrides the output folder and adds another VM argument. Note that the config file name is delimited by `--` because the option prior to it, `--vmargs`, allows multiple arguments:
78+
79+
```bash
80+
java -jar packr.jar --output target/out-mac --vmargs Xms256m -- my-packr-config.json
81+
```
82+
83+
Finally, you can use packr from within your Java code. Just add the JAR file to your project, either manually, or via the following Maven dependency:
6884

6985
```xml
7086
<dependency>
@@ -74,38 +90,84 @@ Finally, you can use packr from within your code. Just add the JAR file to your
7490
</dependency>
7591
```
7692

77-
To invoke packr, you need to create an instance of `Config` and pass it to `Packr.pack()`
93+
To invoke packr, you need to create an instance of `PackrConfig` and pass it to `Packr.pack()`:
7894

7995
```java
80-
Config config = new Config();
81-
config.platform = Platform.windows;
96+
PackrConfig config = new PackrConfig();
97+
config.platform = PackrConfig.Platform.Windows32;
8298
config.jdk = "/User/badlogic/Downloads/openjdk-for-mac.zip";
8399
config.executable = "myapp";
84100
config.classpath = Arrays.asList("myjar.jar");
85101
config.mainClass = "com.my.app.MainClass";
86-
config.vmArgs = Arrays.asList("-Xmx1G");
87-
config.minimizeJre = new String[] { "jre/lib/rt/com/sun/corba", "jre/lib/rt/com/sun/jndi" };
102+
config.vmArgs = Arrays.asList("Xmx1G");
103+
config.minimizeJre = "soft";
88104
config.outDir = "out-mac";
89105

90-
new Packr().pack(config)
106+
new Packr().pack(config);
91107
```
92108

93109
## Minimization
94110

95-
A standard JRE weighs about 90mb unpacked and about 50mb packed. Packr helps you cut down on that size, thus also reducing the download size of your app.
111+
### JRE
96112

97-
To minimize the JRE that is bundled with your app, you have to specify a minimization configuration file via the `minimizejre` flag you supply to Packr. Such a minimization configuration contains the names of files and directories within the JRE to be removed, one per line in the file. E.g.:
113+
A standard OpenJDK JRE weighs about 90 mb unpacked. Packr helps you cut down on that size, thus also reducing the download size of your app.
98114

99-
```
100-
jre/lib/rhino.jar
101-
jre/lib/rt/com/sun/corba
115+
To minimize the JRE that is bundled with your app, you have to specify a minimization configuration file via the `minimizejre` flag you supply to Packr. A minimization configuration is a JSON file containing paths to files and directories within the JRE to be removed.
116+
117+
As an example, have a look at the `soft` profile configuration:
118+
119+
```json
120+
{
121+
"reduce": [
122+
{
123+
"archive": "jre/lib/rt.jar",
124+
"paths": [
125+
"com/sun/corba",
126+
"com/sun/jndi",
127+
"com/sun/media",
128+
"com/sun/naming",
129+
"com/sun/rowset",
130+
"sun/applet",
131+
"sun/corba",
132+
"sun/management"
133+
]
134+
}
135+
],
136+
"remove": [
137+
{
138+
"platform": "*",
139+
"paths": [
140+
"jre/lib/rhino.jar"
141+
]
142+
},
143+
{
144+
"platform": "windows",
145+
"paths": [
146+
"jre/bin/*.exe",
147+
"jre/bin/client"
148+
]
149+
}
150+
]
151+
}
102152
```
103153

104-
This will remove the rhino.jar (about 1.1MB) and all the packages and classes in com.sun.corba from the rt.jar file. To specify files and packages to be removed from the JRE, simply prepend them with `jre/lib/rt/`.
154+
This configuration will unpack `rt.jar`, remove all the listed packages and classes in `com.sun.*` and `sun.*`, then repack `rt.jar` again. By default, the JRE uses zero-compression on its JAR files to make application startup a little faster, so this step will reduce the size of `rt.jar` substantially.
105155

106-
Packr comes with two such configurations out of the box, [`soft`](https://github.com/libgdx/packr/blob/master/src/main/resources/minimize/soft) and [`hard`](https://github.com/libgdx/packr/blob/master/src/main/resources/minimize/hard)
156+
Then, rhino.jar (about 1.1MB) and, in case of a Windows JRE, all executable files in `jre/bin/` and the folder `jre/bin/client/` will be removed.
107157

108-
Additionally, Packr will compress the rt.jar file. By default, the JRE uses zero-compression on the rt.jar file to make application startup a little faster.
158+
Packr comes with two such configurations out of the box, [`soft`](https://github.com/libgdx/packr/blob/master/src/main/resources/minimize/soft) and [`hard`](https://github.com/libgdx/packr/blob/master/src/main/resources/minimize/hard). The `hard` profile removes a few more files, and repacks some additional JAR files.
159+
160+
There's also a new, *experimental* configuration, [`oraclejre8`](https://github.com/libgdx/packr/blob/master/src/main/resources/minimize/oraclejre8), which reduces size of an Oracle 8 JRE following Oracle's redistribution rules described [here](http://www.oracle.com/technetwork/java/javase/jre-8-readme-2095710.html). It also repacks JAR files, reducing (unpacked) JRE size from about 180 mb to 70 mb. **This version is pretty much untested, so please use with care!**
161+
162+
### Classpath
163+
164+
Minimization aside, packr also removes all dynamic libraries which do not match the target platform from your project JAR file(s):
165+
166+
| platform | files removed |
167+
| --- | --- |
168+
| Windows | `*.dylib`, `*.so` |
169+
| Linux | `*.dll`, `*.dylib` |
170+
| MacOS | `*.dll`, `*.so` |
109171

110172
## Output
111173

@@ -144,19 +206,19 @@ outdir/
144206
icons.icns [if config.icon is set]
145207
```
146208

147-
You can further modify the Info.plist to your liking, e.g. add icons, a bundle identifier etc. If your `outdir` has the `.app` extension it will be treated as an application bundle by Mac OS X.
209+
You can further modify the Info.plist to your liking, e.g. add icons, a bundle identifier etc. If your `output` folder has the `.app` extension it will be treated as an application bundle by Mac OS X.
148210

149211
## Executable command line interface
150212

151213
By default, the native executables forward any command line parameters to your Java application's main() function. So, with the configurations above, `./myapp -x y.z` is passed as `com.my.app.MainClass.main(new String[] {"-x", "y.z" })`.
152214

153-
The executables themselves expose an own interface, which has to be explicitly enabled by passing `-c` or `--cli` as the **very first** parameter. In this case, a special delimiter parameter `--` is used to separate the native CLI from parameters to be passed to Java. In this case, the example above would be equal to `./myapp -c [arguments] -- -x y.z`.
215+
The executables themselves expose an own interface, which has to be enabled explicitly by passing `-c` or `--cli` as the **very first** parameter. In this case, the special delimiter parameter `--` is used to separate the native CLI from parameters to be passed to Java. In this case, the example above would be equal to `./myapp -c [arguments] -- -x y.z`.
154216

155217
Try `./myapp -c --help` for a list of available options. They are also listed [here](https://github.com/libgdx/packr/blob/master/src/main/native/README.md#command-line-interface).
156218

157-
> Note: On Windows, the executable does not show any output by default. Here you can use `myapp.exe -c --console --help` to spawn a console window, making terminal output visible.
219+
> Note: On Windows, the executable does not show any output by default. Here you can use `myapp.exe -c --console [arguments]` to spawn a console window, making terminal output visible.
158220
159-
## Building
221+
## Building from source code
160222

161223
If you want to modify the Java code only, it's sufficient to invoke Maven.
162224

@@ -173,7 +235,7 @@ If you want to compile the native executables, please follow [these instructions
173235
* Icons aren't set yet on Windows and Linux, you need to do that manually.
174236
* Minimum platform requirement on MacOS is OS X 10.7.
175237
* JRE minimization is very conservative. Depending on your app, you can carve out stuff from a JRE yourself, disable minimization and pass your custom JRE to packr.
176-
* On MacOS, the JVM is spawned in its own thread by default, which is a requirement of AWT. This does not work with code based on LWJGL3/GLFW, which needs the JVM be spawned on the main thread. You can enforce the latter with the `-XstartOnFirstThread` VM argument in your packr config.
238+
* On MacOS, the JVM is spawned in its own thread by default, which is a requirement of AWT. This does not work with code based on LWJGL3/GLFW, which needs the JVM be spawned on the main thread. You can enforce the latter with adding the `-XstartOnFirstThread` VM argument to your MacOS packr config.
177239

178240
## License & Contributions
179241

example-config-linux.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
],
88
"mainclass": "com.badlogicgames.packr.TestApp",
99
"vmargs": [
10-
"-Xmx1G"
10+
"Xmx1G"
1111
],
1212
"resources": [
1313
"pom.xml",
1414
"src/main/resources"
1515
],
1616
"minimizejre": "soft",
17-
"outdir": "out-lin"
17+
"output": "out-lin"
1818
}

example-config-mac.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
],
88
"mainclass": "com.badlogicgames.packr.TestApp",
99
"vmargs": [
10-
"-Xmx1G"
10+
"Xmx1G"
1111
],
1212
"resources": [
1313
"pom.xml",
1414
"src/main/resources"
1515
],
1616
"minimizejre": "soft",
17-
"outdir": "out-mac"
17+
"output": "out-mac"
1818
}

example-config-windows.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
],
88
"mainclass": "com.badlogicgames.packr.TestApp",
99
"vmargs": [
10-
"-Xmx1G"
10+
"Xmx1G"
1111
],
1212
"resources": [
1313
"pom.xml",
1414
"src/main/resources"
1515
],
1616
"minimizejre": "soft",
17-
"outdir": "out-win"
17+
"output": "out-win"
1818
}

pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,10 @@
111111
<artifactId>minimal-json</artifactId>
112112
<version>0.9.1</version>
113113
</dependency>
114+
<dependency>
115+
<groupId>com.lexicalscope.jewelcli</groupId>
116+
<artifactId>jewelcli</artifactId>
117+
<version>0.8.9</version>
118+
</dependency>
114119
</dependencies>
115120
</project>

0 commit comments

Comments
 (0)