Dynamic loading a class in java with a different package name

后端 未结 3 1494
悲哀的现实
悲哀的现实 2020-12-30 07:04

Is it possible to load a class in Java and \'fake\' the package name/canonical name of a class? I tried doing this, the obvious way, but I get a \"class name doesn\'t match

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 07:26

    Maybe it would be easier to move the API from the default package into a more reasonable spot? It sounds like you don't have access to the source code. I am not sure if the package is encoded into class files, so simply moving the API class might be worth a try. Otherwise, Java decompilers like JAD usually do a good job, so you could change the package name in the decompiled source and compile it again.

提交回复
热议问题