Loading the classes from a jar that is dynamically uploaded through a servlet

41 views
Skip to first unread message

Komal

unread,
Dec 11, 2012, 8:28:50 AM12/11/12
to google-code...@googlegroups.com

I am uploading a jar dynamically through servlet and saving it in my WEB-INF/lib directory. I want to get all the classes annotated with my @annotation,

have used reflections code below without any luck.. the manifest of the jar is readable but the classes are not.. the set of classes is 0


List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
ConfigurationBuilder builder = new ConfigurationBuilder().setScanners(new SubTypesScanner(false), new ResourcesScanner(),
new TypeAnnotationsScanner());
Set<URL> set = ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]));
FilterBuilder filterBuilder = new FilterBuilder().include(FilterBuilder.prefix(exportPackage));
Reflections reflections = new Reflections(builder.setUrls(set).filterInputsBy(filterBuilder));
Set<Class<? extends Object>> classSet = reflections.getTypesAnnotatedWith(MyAnnotation.class);


What changes to the configuration will help get the classes from the jar that is dynamically uploaded..

Komal

unread,
Dec 13, 2012, 12:58:46 AM12/13/12
to google-code...@googlegroups.com
I have tried adding the URLClassLoader to the classLoadersList, but that too dosent seem to help.. 

Also kept the uploaded jar in a separate folder than WEB-INF/lib but the issue remains..

Any suggestions will be highly appreciated.
Reply all
Reply to author
Forward
0 new messages