When packaged into jar,MorphiaUtils.getClasses(packageName) returned empty list.
Closed this issue · 4 comments
ukid commented
ukid commented
For now I overrode ReflecitonUtils.getFromJARFile,and it seems to work fine.Do you have any better idea?
public static Set<Class<?>> getFromJARFile(final ClassLoader loader, final String jar, final String packageName, final boolean mapSubPackages) throws IOException, ClassNotFoundException {
final Set<Class<?>> classes = new HashSet<Class<?>>();
final JarInputStream jarFile = new JarInputStream(new FileInputStream(jar));
try {
JarEntry jarEntry;
do {
jarEntry = jarFile.getNextJarEntry();
if (jarEntry != null) {
String className = jarEntry.getName();
if (className.endsWith(".class")) {
// add this line
className = className.replace("BOOT-INF/classes/", "");
String classPackageName = getPackageName(className);
if (classPackageName.equals(packageName) || (mapSubPackages && isSubPackage(classPackageName, packageName))) {
className = stripFilenameExtension(className);
classes.add(Class.forName(className.replace('/', '.'), true, loader));
}
}
}
} while (jarEntry != null);
} finally {
jarFile.close();
}
return classes;
}
ganchix commented
ganchix commented
The bug is resolved, you can use it now.
I'm going to upload the library in the maven central repository In the coming weeks.
Thanks for everything.
Regards
ukid commented
Thank you