We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have the following directory setup
src +---main | +---java | | +---com | | | \---example | | | \---test | | | \---dynamic | | | | ClassEnumerator.java | | | | | | | \---classes | | | | MainDirTestClass.java | | | | | | | \---subpackage | | | SubPackageTestClass.java | | \---META-INF | | MANIFEST.MF | \---resources \---test \---java
The ClassEnumerator class contains the following main method as well as the methods posted on StackOverflow:
public static void main(String... args0) { getClassesForPackage(Package.getPackage("com.example.test.dynamic")); }
This produces the following error message:
C:\...\test>java -jar ClassEnumeration.jar ClassDiscovery: Package: com.example.test.dynamic becomes Path:com/example/test/dynamic ClassDiscovery: Resource = jar:file:/C:/.../test/ClassEnumeration.jar!/com/example/test/dynamic ClassDiscovery: FullPath = jar:file:/C:/.../test/ClassEnumeration.jar!/com/example/test/dynamic ClassDiscovery: Directory = null ClassDiscovery: JarEntry: com/example/test/dynamic/ClassEnumerator.class ClassDiscovery: className = com.example.test.dynamic.ClassEnumerator ClassDiscovery: JarEntry: com/example/test/dynamic/classes/ ClassDiscovery: className = com.example.test.dynamices. Exception in thread "main" java.lang.RuntimeException: ClassNotFoundException loading com.example.test.dynamices. at com.example.test.dynamic.ClassEnumerator.getClassesForPackage(ClassEnumerator.java:75) at com.example.test.dynamic.ClassEnumerator.main(ClassEnumerator.java:87)
Any idea where the "...es." comes from in "com.example.test.dynamices"?
The text was updated successfully, but these errors were encountered:
The problem is partially this line, where the .class replacement happens last - after all slashes were turned into dots:
String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", ""); // entryName: com/example/test/dynamic/classes/
An addition to the if statement and a bit of reordering gets us this conditional block, which now seems to work as expected:
if(entryName.startsWith(relPath) && entryName.endsWith(".class") && entryName.length() > (relPath.length() + "/".length())) { System.out.println("ClassDiscovery: JarEntry: " + entryName); String className = entryName.replace(".class", "").replace('/', '.').replace('\\', '.'); System.out.println("ClassDiscovery: className = " + className); try { classes.add(Class.forName(className)); } catch (ClassNotFoundException e) { throw new RuntimeException("ClassNotFoundException loading " + className); } }
Sorry, something went wrong.
No branches or pull requests
I have the following directory setup
The ClassEnumerator class contains the following main method as well as the methods posted on StackOverflow:
This produces the following error message:
Any idea where the "...es." comes from in "com.example.test.dynamices"?
The text was updated successfully, but these errors were encountered: