One can specify --obfuscationlevel when invoking the bck2brwsr compiler from command line. Forking external Java when calling into the compiler to prevent "out of perm gem" errors.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 import java.io.BufferedWriter;
21 import java.io.FileWriter;
22 import java.io.IOException;
23 import java.io.Writer;
25 /** Generator of JavaScript from bytecode of classes on classpath of the VM
28 * @author Jaroslav Tulach <jtulach@netbeans.org>
33 public static void main(String... args) throws IOException {
34 final String obfuscate = "--obfuscatelevel";
36 if (args.length < 2) {
37 System.err.println("Bck2Brwsr Translator from Java(tm) to JavaScript, (c) Jaroslav Tulach 2012");
38 System.err.println("Usage: java -cp ... -jar ... [");
39 System.err.print(obfuscate);
40 System.err.print(" [");
42 for (ObfuscationLevel l : ObfuscationLevel.values()) {
44 System.err.print('|');
46 System.err.print(l.name());
50 System.err.println("] <file_to_generate_js_code_to> java/lang/Class org/your/App ...");
54 ObfuscationLevel obfLevel = ObfuscationLevel.NONE;
55 StringArray classes = new StringArray();
56 String generateTo = null;
57 for (int i = 0; i < args.length; i++) {
58 if (obfuscate.equals(args[i])) { // NOI18N
61 obfLevel = ObfuscationLevel.valueOf(args[i]);
62 } catch (Exception e) {
63 System.err.print(obfuscate);
64 System.err.print(" parameter needs to be followed by one of ");
66 for (ObfuscationLevel l : ObfuscationLevel.values()) {
68 System.err.print(", ");
70 System.err.print(l.name());
78 if (generateTo == null) {
81 classes = classes.addAndNew(args[i]);
84 try (Writer w = new BufferedWriter(new FileWriter(generateTo))) {
85 Bck2Brwsr.newCompiler().
86 obfuscation(obfLevel).
87 addRootClasses(classes.toArray()).
88 resources(Main.class.getClassLoader()).