Announcement Announcement Module
Collapse
No announcement yet.
ClassPathScanningCandidateComponentProvider not work with jars? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClassPathScanningCandidateComponentProvider not work with jars?

    Hi, All

    I need to scan through classes in some jars to generate a report.

    So I simply use ClassPathScanningCandidateComponentProvider with annotation filter.

    It works fine in IDE, but when I run this application from within Ant, ClassPathScanningCandidateComponentProvider finds nothing.

    I think the class path has been correctly set, since Class.forName gets the right class.

    I am using ClassPathScanningCandidateComponentProvider alone without any Spring context. Is it something wrong within it? Could some help me? Thanks!


    Regards,
    Chuan

  • #2
    After all, it seems that certain format of package name does not play very well. Thanks

    Comment


    • #3
      Same problem?

      did you ever find a solution? what version of Ant where you using? and JVM? if i put the jar i want to scan into the Ant lib then everything works. some sort of classloader issue whereby Spring doesn't get a handle to the Ant classloader.....
      Last edited by young_matthewd; Sep 28th, 2009, 10:04 AM.

      Comment


      • #4
        I am having the same problem

        Does anyone else know why the following would not work?
        Code:
          public static List<Class> getComponentClasses(Class clazz, String basePackage)
             {
            	 basePackage = (basePackage == null )? "" : basePackage;  
                 List<Class> classes = new ArrayList<Class>();  
            
                 ClassPathScanningCandidateComponentProvider scanner=new ClassPathScanningCandidateComponentProvider(false);
                 scanner.addIncludeFilter(new AssignableTypeFilter(clazz));
                 for (BeanDefinition candidate : scanner.findCandidateComponents(basePackage)) {  
                     try {  
        //                 Class<?> cls = ClassUtils.resolveClassName(candidate.getBeanClassName(),  
        //                         ClassUtils.getDefaultClassLoader());  
                       Class cls = ClassUtils.resolveClassName(candidate.getBeanClassName(),  
                              scanner.getResourceLoader().getClassLoader());  
                         classes.add((Class) cls);  
                     } catch (Throwable ex) {  
                         LOGGER.log(Level.FATAL,"Unable to parse bean candidate.",ex);  
                     }  
                 }  
                 return classes;   
             }
        I am calling it via
        Code:
        MyClassScanner.getComponentClasses(org.quartz.Job.class,null);

        It finds all my classes that implement the job interface that are in my war but not the ones that I have in jars (inside or outside the war).
        Last edited by solid; Aug 17th, 2010, 05:18 PM.

        Comment

        Working...
        X