-
-
Save nmr8acme/7e41fd2c03f8681f14c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pg; | |
@interface Keep { | |
} | |
public class Main { | |
public static void main(String[] args) throws Exception { | |
System.out.println( | |
Class.forName(System.getenv("THE_CLASS")) | |
.getMethods()[0].invoke(null)); | |
} | |
} | |
@Keep | |
class Helper { | |
@Keep public static String getString() { | |
return "success!"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go: | |
$(RM) -r bin out.jar | |
mkdir bin | |
$(JAVAC) -d bin Main.java | |
$(JAVA) -jar $(PROGUARD_JAR) -verbose -include proguard.cfg | |
$(JAVA) -classpath bin pg.Main | |
$(JAVA) -classpath out.jar pg.Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-dontpreverify | |
-dontoptimize | |
-injars bin | |
-outjars out.jar | |
-libraryjars <java.home>/lib/rt.jar | |
-keepattributes *Annotation* | |
-keep class pg.Main { | |
public static void main(java.lang.String[]); | |
} | |
# Uncommenting this makes the program work. | |
#-keep class pg.Keep | |
-keep @pg.Keep class * | |
-keepclassmembers class * { | |
@pg.Keep *; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ make JAVAC=javac JAVA=java PROGUARD_JAR=/home/dreiss/stuff/build/proguard4.9beta2/lib/proguard.jar THE_CLASS="pg.Helper" | |
rm -f -r bin out.jar | |
mkdir bin | |
javac -d bin Main.java | |
java -jar /home/dreiss/stuff/build/proguard4.9beta2/lib/proguard.jar -verbose -include proguard.cfg | |
ProGuard, version 4.9 beta2 | |
Reading input... | |
Reading program directory [/home/dreiss/work/proguard-test/bin] | |
Reading library jar [/home/dreiss/opt/jdk1.6.0_35/jre/lib/rt.jar] | |
Initializing... | |
Ignoring unused library classes... | |
Original number of library classes: 17459 | |
Final number of library classes: 48 | |
Shrinking... | |
Removing unused program classes and class elements... | |
Original number of program classes: 3 | |
Final number of program classes: 2 | |
Obfuscating... | |
Writing output... | |
Preparing output jar [/home/dreiss/work/proguard-test/out.jar] | |
Copying resources from program directory [/home/dreiss/work/proguard-test/bin] | |
java -classpath bin pg.Main | |
success! | |
java -classpath out.jar pg.Main | |
Exception in thread "main" java.lang.ClassNotFoundException: pg.Helper | |
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) | |
at java.security.AccessController.doPrivileged(Native Method) | |
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) | |
at java.lang.ClassLoader.loadClass(ClassLoader.java:306) | |
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) | |
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) | |
at java.lang.Class.forName0(Native Method) | |
at java.lang.Class.forName(Class.java:169) | |
at pg.Main.main(Unknown Source) | |
make: *** [go] Error 1 | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment