Giter Club home page Giter Club logo

java-class-enumerator's Issues

License

I am using this class file as a library in Fake Java OS. Because of that, can you add a license file describing which license is used in this file?

It can not get the class, if run in testcase.

I run with the Junit in test-class,it cann't get the files in class package.
So that means this class can not work with unit test.
Thanks a lot:)

PS:what about use this?
Thread.currentThread().getContextClassLoader().getResources

FileNotFoundException if path or file name contains a space while iterating over a jar file

I get a FileNotFoundException when going through a jar file if the jar file or its path contain a space:

C:\Users\foobar\test>java -jar "Class Enumeration.jar"
ClassDiscovery: Package: com.example.test.dynamic becomes Path:com/example/test/dynamic
ClassDiscovery: Resource = jar:file:/C:/Users/foobar/test/Class%20Enumeration.jar!/com/example/test/dynamic
ClassDiscovery: FullPath = jar:file:/C:/Users/foobar/test/Class%20Enumeration.jar!/com/example/test/dynamic
ClassDiscovery: Directory = null
Exception in thread "main" java.lang.RuntimeException: com.example.test.dynamic (null) does not appear to be a valid package
        at com.example.test.dynamic.ClassEnumerator.getClassesForPackage(ClassEnumerator.java:80)
        at com.example.test.dynamic.ClassEnumerator.main(ClassEnumerator.java:87)
Caused by: java.io.FileNotFoundException: C:\Users\foobar\test\Class%20Enumeration.jar (The system cannot find the file specified)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(Unknown Source)
        at java.util.zip.ZipFile.<init>(Unknown Source)
        at java.util.jar.JarFile.<init>(Unknown Source)
        at java.util.jar.JarFile.<init>(Unknown Source)
        at com.example.test.dynamic.ClassEnumerator.getClassesForPackage(ClassEnumerator.java:62)
        ... 1 more

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"));
    }

I'm running on Win 7, 64bit. Here is my Java version:

java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) Client VM (build 25.20-b23, mixed mode, sharing)

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

ClassNotFound Exception

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"?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.