diff --git a/example-config-linux.json b/example-config-linux.json index fe1e7c3e..6d95e739 100644 --- a/example-config-linux.json +++ b/example-config-linux.json @@ -11,6 +11,6 @@ "pom.xml", "src/main/resources" ], - "minimizejre": true, + "minimizejre": "soft", "outdir": "out-lin" } diff --git a/example-config-mac.json b/example-config-mac.json index 08ffd80f..a8e0e2b2 100644 --- a/example-config-mac.json +++ b/example-config-mac.json @@ -11,6 +11,6 @@ "pom.xml", "src/main/resources" ], - "minimizejre": true, + "minimizejre": "soft", "outdir": "out-mac" } \ No newline at end of file diff --git a/example-config-windows.json b/example-config-windows.json index b7376163..d3065f37 100644 --- a/example-config-windows.json +++ b/example-config-windows.json @@ -11,6 +11,6 @@ "pom.xml", "src/main/resources" ], - "minimizejre": true, + "minimizejre": "soft", "outdir": "out-win" } \ No newline at end of file diff --git a/src/main/java/com/badlogicgames/packr/Packr.java b/src/main/java/com/badlogicgames/packr/Packr.java index d3a74d0b..0bdea808 100644 --- a/src/main/java/com/badlogicgames/packr/Packr.java +++ b/src/main/java/com/badlogicgames/packr/Packr.java @@ -186,7 +186,9 @@ private void minimizeJre(Config config, File outDir) throws IOException { FileUtils.deleteDirectory(new File(outDir, "jre/bin")); } for(String minimizedDir : config.minimizeJre) { - FileUtils.deleteDirectory(new File(outDir, minimizedDir)); + File file = new File(outDir, minimizedDir); + if(file.isDirectory()) FileUtils.deleteDirectory(new File(outDir, minimizedDir)); + else file.delete(); } new File(outDir, "jre/lib/rhino.jar").delete(); @@ -279,34 +281,18 @@ public static void main(String[] args) throws IOException { config.vmArgs = Arrays.asList(arguments.get("vmargs").split(";")); } config.outDir = arguments.get("outdir"); - if(arguments.get("minimizejre").equals("hard") || arguments.get("minimizejre").equals("true")) - { - config.minimizeJre = new String[] { - "jre/lib/rt/com/sun/corba", "jre/lib/rt/com/sun/jmx", "jre/lib/rt/com/sun/jndi", - "jre/lib/rt/com/sun/media", "jre/lib/rt/com/sun/naming", - "jre/lib/rt/com/sun/org", "jre/lib/rt/com/sun/rowset", - "jre/lib/rt/com/sun/script", "jre/lib/rt/com/sun/xml", "jre/lib/rt/sun/applet", - "jre/lib/rt/sun/corba", "jre/lib/rt/sun/management" - }; - } - else if(arguments.get("minimizejre").equals("soft")) - { - config.minimizeJre = new String[] { - "jre/lib/rt/com/sun/corba", "jre/lib/rt/com/sun/jndi", - "jre/lib/rt/com/sun/media", "jre/lib/rt/com/sun/naming", - "jre/lib/rt/com/sun/rowset", - "jre/lib/rt/sun/applet", - "jre/lib/rt/sun/corba", "jre/lib/rt/sun/management" - }; - } - - else if(arguments.get("minimizejre").equals("false")) - { - config.minimizeJre = null; - } - else if(arguments.get("minimizejre") != null) - { - config.minimizeJre = FileUtils.readFileToString(new File(arguments.get("minimizejre"))).split("\r?\n"); + if(arguments.get("minimizejre") != null) { + if(new File(arguments.get("minimizejre")).exists()) { + config.minimizeJre = FileUtils.readFileToString(new File(arguments.get("minimizejre"))).split("\r?\n"); + } else { + InputStream in = Packr.class.getResourceAsStream("/minimize/" + arguments.get("minimizejre")); + if(in != null) { + config.minimizeJre = IOUtils.toString(in).split("\r?\n"); + in.close(); + } else { + config.minimizeJre = new String[0]; + } + } } if(arguments.get("resources") != null) config.resources = Arrays.asList(arguments.get("resources").split(";")); new Packr().pack(config); @@ -327,32 +313,18 @@ else if(arguments.get("minimizejre") != null) } } config.outDir = json.get("outdir").asString(); - if(json.get("minimizejre").asString().equals("hard") || json.get("minimizejre").asString().equals("true")) - { - config.minimizeJre = new String[] { - "jre/lib/rt/com/sun/corba", "jre/lib/rt/com/sun/jmx", "jre/lib/rt/com/sun/jndi", - "jre/lib/rt/com/sun/media", "jre/lib/rt/com/sun/naming", - "jre/lib/rt/com/sun/org", "jre/lib/rt/com/sun/rowset", - "jre/lib/rt/com/sun/script", "jre/lib/rt/com/sun/xml", "jre/lib/rt/sun/applet", - "jre/lib/rt/sun/corba", "jre/lib/rt/sun/management" - }; - } - else if(json.get("minimizejre").asString().equals("soft")) - { - config.minimizeJre = new String[]{ - "jre/lib/rt/com/sun/corba", "jre/lib/rt/com/sun/jndi", - "jre/lib/rt/com/sun/media", "jre/lib/rt/com/sun/naming", - "jre/lib/rt/com/sun/rowset", - "jre/lib/rt/sun/applet", - "jre/lib/rt/sun/corba", "jre/lib/rt/sun/management" - }; - } - else if(json.get("minimizejre").asString().equals("false")) - { - config.minimizeJre = null; - } - else if(json.get("minimizejre") != null) { - config.minimizeJre = FileUtils.readFileToString(new File(json.get("minimizejre").asString())).split("\r?\n"); + if(json.get("minimizejre") != null) { + if(new File(json.get("minimizejre").asString()).exists()) { + config.minimizeJre = FileUtils.readFileToString(new File(json.get("minimizejre").asString())).split("\r?\n"); + } else { + InputStream in = Packr.class.getResourceAsStream("/minimize/" + json.get("minimizejre")); + if(in != null) { + config.minimizeJre = IOUtils.toString(in).split("\r?\n"); + in.close(); + } else { + config.minimizeJre = new String[0]; + } + } } if(json.get("resources") != null) { config.resources = toStringArray(json.get("resources").asArray()); @@ -384,9 +356,8 @@ private static void printHelp() { System.out.println("-appjar ... JAR file containing code and assets to be packed"); System.out.println("-mainclass ... fully qualified main class name, e.g. com/badlogic/MyApp"); System.out.println("-vmargs ... arguments passed to the JVM, e.g. -Xmx1G, separated by ;"); - System.out.println("-minimizejre ... minimize the JRE, can remove unneeded folders but could break your app."); - System.out.println(" Can be false, a config file or how hard to push things out (soft or hard, true is an alias for hard)."); - System.out.println(" Config files are just lists of folders in rt.jar to remove, one per line."); + System.out.println("-minimizejre ... minimize the JRE by removing folders and files specified in the config file"); + System.out.println(" three config files come with packr: 'soft' and 'hard' which may or may not break your app"); System.out.println("-resources ... additional files and folders to be packed next to the"); System.out.println(" executable. Entries are separated by a ;"); System.out.println("-outdir ... output directory"); diff --git a/src/main/resources/minimize/hard b/src/main/resources/minimize/hard new file mode 100644 index 00000000..002cec72 --- /dev/null +++ b/src/main/resources/minimize/hard @@ -0,0 +1,12 @@ +jre/lib/rt/com/sun/corba +jre/lib/rt/com/sun/jmx +jre/lib/rt/com/sun/jndi +jre/lib/rt/com/sun/media +jre/lib/rt/com/sun/naming +jre/lib/rt/com/sun/org +jre/lib/rt/com/sun/rowset +jre/lib/rt/com/sun/script +jre/lib/rt/com/sun/xml +jre/lib/rt/sun/applet +jre/lib/rt/sun/corba +jre/lib/rt/sun/management \ No newline at end of file diff --git a/src/main/resources/minimize/soft b/src/main/resources/minimize/soft new file mode 100644 index 00000000..8dc3407e --- /dev/null +++ b/src/main/resources/minimize/soft @@ -0,0 +1,8 @@ +jre/lib/rt/com/sun/corba +jre/lib/rt/com/sun/jndi +jre/lib/rt/com/sun/media +jre/lib/rt/com/sun/naming +jre/lib/rt/com/sun/rowset +jre/lib/rt/sun/applet +jre/lib/rt/sun/corba +jre/lib/rt/sun/management \ No newline at end of file