Hi i use yguard ant task to obfuscate my project, it goes well with renaming my java classes, and corresponding bean in spring xml files, but since the getter and setter methods are also renamed in java, the property names in spring injection does not match.. So i am unable to proceed. can any one tell me how to exclude setters and getters alone from obfuscating?
1 Answers
YGuard is not very good in this part, but why don't you try ProGaurd?
You can refer to ProGaurd examples section (http://proguard.sourceforge.net/index.html#manual/examples.html) which say:
Processing bean classes
If your application, applet, servlet, library, etc., makes extensive use of introspection on bean classes to find bean editor classes, or getter and setter methods, then configuration may become painful. There's not much else you can do than making sure the bean class names, or the getter and setter names don't change. For instance:
-keep public class mypackage.MyBean {
public void setMyProperty(int);
public int getMyProperty();
}
-keep public class mypackage.MyBeanEditor
If there are too many elements to list explicitly, wildcards in class names and method signatures might be helpful. This example should encompasses all possible setters and getters in classes in the package mybeans:
-keep class mybeans.** {
void set*(***);
void set*(int, ***);
boolean is*();
boolean is*(int);
*** get*();
*** get*(int);
}
The '***' wildcard matches any type (primitive or non-primitive, array or non-array). The methods with the 'int' arguments matches properties that are lists.
and if you also use annotations in your application:
Processing resource injection
If your application is using Java EE-style resource injection, the application container will automatically assign instances of resource classes to fields and methods that are annotated with @Resource. The container applies introspection, even accessing private class members directly. It typically constructs a resource name based on the type name and the class member name. We then have to avoid that such class members are removed or renamed:
-keepclassmembers class * {
@javax.annotation.Resource *;
}
The Spring framework has another similar annotation @Autowired:
-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired *;
}

- 37,782
- 12
- 108
- 140

- 745
- 1
- 9
- 22