choigv / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

FileNotFoundException when using in JBoss 5.1.0 #142

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I am trying to use reflections in our project to support custom annotations.Our 
project is J2EE application deployed in JBoss 5.1.0. In one of our classes 
(SystemMonitor) that is annotated with org.jboss.ejb3.annotation.Service 
annotation I am initializing Reflections and trying to get handle to all those 
classes that are annotated using our custom annotation. Here's the code snippet:

try {
      Vfs.addDefaultURLTypes(new UrlTypeVFS());
      Reflections reflections = new Reflections("com.foo");
      Set<Class<?>> typesAnnotatedWith = reflections.getTypesAnnotatedWith(TestAnnotation.class);
      // Currently just logging...eventually some more meaningful stuff will be done
      for (Class<?> class1 : typesAnnotatedWith) {
        //TestAnnotation is our custom annotation. 
        TestAnnotation annotation = class1.getAnnotation(TestAnnotation.class);
        log.info("Class with TestAnnotation annotation is {0} and its name is {1}", class1.getName(), annotation.name());
        Annotation[] annotations = class1.getAnnotations();
        StringBuffer buff = new StringBuffer();
        buff.append("Other annotations for this class are as follows");
        for (int i = 0; i < annotations.length; i++) {
          buff.append(" ").append(annotations[i]).append(",");
        }
        log.info(buff.toString());
      }
    } catch(Exception e){
      log.error("Error when scanning the annotations", e);
    }

When our application is getting deployed and start() method of the 
SystemMonitor class is invoked the above code gets executed. I keep on getting 
following exception:

2013-01-24 15:12:39,877 ERROR [STDERR] (main) java.io.FileNotFoundException: 
\Program Files (x86)\NA\deploy\server.ear\foo.jar! (The system cannot find the 
file specified)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
java.util.zip.ZipFile.open(Native Method)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
java.util.zip.ZipFile.<init>(ZipFile.java:214)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
java.util.zip.ZipFile.<init>(ZipFile.java:144)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
java.util.jar.JarFile.<init>(JarFile.java:152)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
java.util.jar.JarFile.<init>(JarFile.java:89)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
org.reflections.vfs.UrlTypeVFS.createDir(UrlTypeVFS.java:38)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
org.reflections.vfs.Vfs.fromURL(Vfs.java:98)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
org.reflections.vfs.Vfs.fromURL(Vfs.java:90)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
org.reflections.Reflections.scan(Reflections.java:165)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
org.reflections.Reflections.<init>(Reflections.java:94)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
org.reflections.Reflections.<init>(Reflections.java:135)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
org.reflections.Reflections.<init>(Reflections.java:108)
2013-01-24 15:12:39,877 ERROR [STDERR] (main)   at 
com.brocade.dcm.system.monitor.SystemMonitor.start(SystemMonitor.java:266)

What is the expected output? What do you see instead?
Even though the jar file is present in the specified path I keep on getting 
FileNotFoundException. I also noticed that "C:\" is missing from the file name. 
I enabled debug logs for org.reflections and Reflections class prints the urls 
properly with "C:\" in the path. Here's the output from debug logs of 
Reflections:
2013-01-24 15:12:39,861 DEBUG [org.reflections.Reflections] (main) going to 
scan these urls:
    vfszip:/C:/Program Files (x86)/NA/deploy/server.ear/foo.jar/

What version of the product are you using? On what operating system?
I am using the latest version of reflections (0.9.8). System details are as 
follows:
OS: Windows XP (64 bit)
Application server: JBoss 5.1.0 GA

Please provide any additional information below.

Original issue reported on code.google.com by atul.ksh...@gmail.com on 24 Jan 2013 at 11:51

GoogleCodeExporter commented 9 years ago
OK, so I debugged this further and found that the issue was because we have 
exploded ear deployment. replaceZipSeparatorStartingFrom method in UrlTypeVFS 
appends a "!" at the end and that results in FileNotFoundException. I have 
fixed this as follows in UrlTypeVFS:
                 if (zipPath.trim().length() == 0) {
            url = new URL(prefix + "/" + zipFile);
        } else {
            url = new URL(prefix + "/" + zipFile + "!" + zipPath);
        }
So only if zipPath has any contents we will add "!" else we will not. This will 
be required for exploded deployments like ours.

Original comment by atul.ksh...@gmail.com on 25 Jan 2013 at 7:22

GoogleCodeExporter commented 9 years ago
fixed on trunk, comments are welcomed

Original comment by ronm...@gmail.com on 20 Feb 2013 at 9:04