Search code examples
javadeobfuscation

Accessing the package with the same name as a class in a *.jar


I have a *.jar file and i want to use some classes from it. Among the others, it contains class "a" from package "com.a.a" and package "com.a.a.a.a.e" with class "a". When i try to access the class as "com.a.a.a.a.e.a", there is an error: com.a.a.a.a cannot be resolved to a type. It happens because compiler tries to get the field "a" of class "com.a.a.a" rather than package "com.a.a.a.a". I also tried to import this class, but it makes no difference, and i get the error "The import com.a.a.a.a cannot be resolved".

Is there any way to use the class "com.a.a.a.a.e.a"? Are there any tools that are able to rename classes in *.jar? Or may be reflection can help here?


Solution

  • The JAR you're trying to use has most likely been obfuscated, probably for the purpose of preventing what you're trying to do. Some Java obfuscators change the package, class, method, and variable names to violate the JLS but still be valid compiled bytecode; that appears to be exactly what has been done to this JAR. It will be very difficult to make sense of the de-compiled code in that case.

    JARs that are obfuscated usually leave just their public API un-obfuscated for your code to use; everything else is scrambled to prevent you from de-compiling it and/or using it directly.