我想用proguard来混淆JAXB代码。这是完整的Java类代码:
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlType;
@XmlType(propOrder =
{
"setting", "subsystems"
})
@XmlAccessorType(XmlAccessType.FIELD)
public class ProfileImpl implements Profile
{
@XmlAttribute
private String name;
@XmlAttribute
private final String version;
@XmlElementWrapper(name = "subsystems")
@XmlElement(name = "subsystem")
private List<SubsystemImpl> subsystems;
private SettingImpl setting;
public ProfileImpl()
{
this.version = "1.0";
this.name = "default";
}
public ProfileImpl(String name, SettingImpl setting, List<SubsystemImpl> subsystems, String version)
{
this.name = name;
this.setting = setting;
this.version = version;
this.subsystems = subsystems;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public List<SubsystemImpl> getSubsystems()
{
return subsystems;
}
public void setSubsystems(List<SubsystemImpl> subsystems)
{
this.subsystems = subsystems;
}
public SettingImpl getSetting()
{
return setting;
}
public void setSetting(SettingImpl setting)
{
this.setting = setting;
}
}
但是当我运行代码时,我得到了:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 4 counts of IllegalAnnotationExceptions
Property c is present but not specified in @XmlType.propOrder
this problem is related to the following location:
at private java.util.List org.settings.loader.osgi.impl.jaxb.ProfileImpl.c
at org.settings.loader.osgi.impl.jaxb.ProfileImpl
at private java.util.List org.settings.loader.osgi.impl.jaxb.f.b
at org.settings.loader.osgi.impl.jaxb.f
Property d is present but not specified in @XmlType.propOrder
this problem is related to the following location:
at private org.settings.loader.osgi.impl.jaxb.d org.settings.loader.osgi.impl.jaxb.ProfileImpl.d
at org.settings.loader.osgi.impl.jaxb.ProfileImpl
at private java.util.List org.settings.loader.osgi.impl.jaxb.f.b
at org.settings.loader.osgi.impl.jaxb.f
我如何解决问题?
我尝试了这个Proguard配置,以便跳过Class混淆:
<option>-keep public class org.settings.loader.osgi.impl.jaxb.ProfileImpl{public *; private *;} -keepattributes Exceptions, *Annotation*, InnerClasses, Signature, SourceFile, EnclosingMethod -dontshrink -dontoptimize -keepparameternames</option>
答案 0 :(得分:1)
要使proguard处理注释,请尝试将以下内容添加到参数
-keep public class javax.xml.bind.**
-keep public class org.settings.loader.osgi.impl.jaxb.ProfileImpl implements org.settings.loader.osgi.impl.jaxb.Profile
-keepattributes *Annotation*
http://proguard.sourceforge.net/manual/examples.html#annotations
<强>更新强>
我冒昧地修改你的代码,如下所示。 请检查在此修改后是否包含参数后面的代码会有所不同。
public class ProfileImpl implements Profile
{
private String name;
private final String version;
private List<SubsystemImpl> subsystems;
private SettingImpl setting;
public ProfileImpl(){
this.version = "1.0";
this.name = "default";
}
public ProfileImpl(String name, SettingImpl setting, List<SubsystemImpl> subsystems, String version){
this.name = name;
this.setting = setting;
this.version = version;
this.subsystems = subsystems;
}
@XmlAttribute(name = "name")
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
@XmlAttribute(name = "version")
public String getVersion(){
return version;
}
public void setVersion(String version){
this.version = version;
}
@XmlElementWrapper(name = "subsystems")
@XmlElement(name = "subsystem")
public List<SubsystemImpl> getSubsystems(){
return subsystems;
}
public void setSubsystems(List<SubsystemImpl> subsystems){
this.subsystems = subsystems;
}
public SettingImpl getSetting(){
return setting;
}
public void setSetting(SettingImpl setting){
this.setting = setting;
}
}
答案 1 :(得分:0)
请在支持顺序中添加“名称”和“版本”,因为访问类型定义为字段