We help IT Professionals succeed at work.

Proguard Top Level Obfuscation

lcor
lcor asked
on
Medium Priority
1,938 Views
Last Modified: 2013-11-24
Hopefully, I can find someone with some Proguard JAVA obfuscation experience.

Here's their website, http://proguard.sourceforge.net/

I have a java servlet application with a directory structure as follows:

servletA.java
servletB.java
somepackage/ACode.java
somepackage/BCode.java
anotherpackage/CCode.java

I'm finding when I run proguard on this application using ant and specify the directory at this level, the obfuscated output jar file looks like this.

servletA.java
servletB.java
x/A.class
x/B.class
x/C.class

That is, the top level servlets don't get obfuscated. I've attached the proguard configuration file.
Does anyone know how to configure proguard to obfuscate the top level servlets?

x comes from the defaultpackage specification in the configuration file.




-injars '..\app.jar'
-outjars '..\o_app.jar'
 
-libraryjars '..\lib\rt_6_0.jar'
-libraryjars '..\lib\servlet-api.jar'
 
-defaultpackage x
-verbose
 
# Keep - Servlets. Keep all extensions of javax.servlet.Servlet.
-keep public class * extends javax.servlet.Servlet
 
# Also keep - Enumerations. Keep a method that is required in enumeration
# classes.
-keepclassmembers class * extends java.lang.Enum {
    public **[] values();
}
 
# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembernames class * {
    native <methods>;
}
 
#Javascript classes
-keepnames class netscape.javascript.JSObject
-keepnames class netscape.javascript.JSException
 
# Remove debugging - Throwable_printStackTrace calls. Remove all invocations of
# Throwable.printStackTrace().
-assumenosideeffects public class java.lang.Throwable {
    public void printStackTrace();
}
 
# Remove debugging - All Log4j API calls. Remove all invocations of the
# Log4j API whose return values are not used.
-assumenosideeffects public class org.apache.log4j.** {
    <methods>;
}

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
Those top level classes should be in a package anyway, so why not move them into one?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
> -keep public class * extends javax.servlet.Servlet

your telling it to keep servlets

which you'd want to do so your config does not break

Author

Commented:
I figured moving to a package was what I needed to do but was *hoping* otherwise.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
we teach our students and web developers to always use packages. Avoids all the gotchas encountered when using the default package.
Good to hear you got it sorted :)

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.