I want to get package name from a .class file, but after trying to use org.apache.bcel
, I am not satisfied with it because there are always some classes which can not be parsed.
the rate is about 20 over 500.
So, is there any other library which can get the package name from a class file?
Edit: this is how I get a package name from a class file now. This can achieve my goal, but some class files can not be parsed, so I want to know is there a better way.
import org.apache.bcel.classfile.ClassParser;
String filePath = "/tmp/Test.class"
ClassParser classParser = new ClassParser(filePath);
JavaClass javaClass;
try {
javaClass = classParser.parse();
} catch (IOException | ClassFormatException e) {
System.out.println(filePath);
}
String packageName = javaClass.getPackageName();
MyObject.class
using reflection - MarkgetPackage()
of aClass
object should return thePackage
. CallinggetName()
on it return the name. - UninformedUserClassLoader
for that. Still, that's all possible and probably worth a try. - OhleCclassParser.parse()
throws an exception? If so, which one (and with what message)? - OhleC