users@jaxb.java.net

Re: Classpath scanning for classes

From: Brian Pontarelli <brian_at_pontarelli.com>
Date: Wed, 11 Jun 2008 10:10:04 -0600

I've done just that in the Java.net Commons trunk. It is in a class
called ClassClassLoaderResolver and it leverages ASM to do the byte code
parsing. ASM is *MUCH* faster than loading the class into the JVM. Feel
free to take a look and see:

https://java-net-commons.dev.java.net

I use it in JCatapult (http://www.jcatapult.org) to locate Guice modules
dynamically as well as in the new JCatapult MVC to find class annotated
with @Action, which are controllers. It works really well. The version
on trunk should work and you can just copy and paste it into your project.

-bp


Kohsuke Kawaguchi wrote:
>
> Thank you.
>
> I'd imagine a little glue code that uses this to figure out classes
> with a JAXB annotation and then return it as Class[] would be a nice
> JAXB commons project.
>
> From there, people can easily create JAXBContext.
>
> Would you be interested in writing on, Dimitris? :-)
>
> Dimitris Andreou wrote:
>> Hi Koshuke,
>> I'm at SpringOne conference @ Belgium. I see that spring (2.5) has a
>> new utility that scans classes out of the classpath (searching for
>> some annotated classes).
>> Although I was not able to find the code (yet), it sounds like that
>> could be modified/used to alleviate the need for XmlSeeAlso. Well,
>> there are caveats for you
>> (or, your replacement anyway! :)) to consider though. It supports
>> either directories or jar files, and parses .class files with ASM to
>> avoid actually loading them.
>> And it uses some package-prefix filtering, or else it would be hugely
>> slow.
>> Even if the need of an annotation won't be completely eliminated (you
>> would still need a package prefix to look for...), maybe another
>> annotation, or XmlSeeAlso itself,
>> could handle package declarations, and would look in them for subtypes.
>>
>> Anyway, just dropped a note in case you would find this interesting.
>
>