Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to keep class file "package-info.class" generated by JAXB during proguard obfuscation step

Tags:

xml

jaxb

proguard

I have a problem, I have some JAXB generated java files between which there is the well known "package-info.java" which just contains 2 lines of code, an annotation and a package definition:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://it.tms.project/input")
package it.tms.project.jaxb.input;

now, when compiled this file produces a normal .class file but when I try to obfuscate it proguard doesn't add it to the obfuscated output.jar, I suppose that's because it doesn't contain any Class or something and no other java file refers to it. I've tried some proguard options to get rid of the problem but no one of this was good:

-keepparameternames
-keepattributes Exceptions,InnerClasses,Signature,SourceFile,EnclosingMethod
-keeppackagenames it.tms.project.jaxb.input
-dontshrink
-dontoptimize

-keepattributes *Annotation* (I thought this one would work but I was wrong)

-keepclassmembernames class * {
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}

Now I just need some option to explicitly tell proguard to don't obfuscate the file I desire but just add it to the output.jar as is, how can I do that? Keep in mind that options like "keep class * {}" don't work because the file doesn't contain any class. Thank you to anyone for your answers and please complete your messages writing FORZA NAPOLI!

like image 348
BitRider Avatar asked Oct 11 '22 03:10

BitRider


1 Answers

As far as ProGuard is concerned, the compiled class is a class like any other. By default, ProGuard discards it however, since it is not used (except by introspection). You can keep it with:

-keep class it.tms.project.jaxb.input.package-info

As you've noticed, you probably want to keep the annotation on this class too:

-keepattributes *Annotation*
like image 157
Eric Lafortune Avatar answered Oct 14 '22 07:10

Eric Lafortune