java - field.getAnnotations() returns empty array when run on a tomcat server, but returns correct annotation when run as a standalone -


i trying dynamically create , load class in application. class has annotations on 1 of member fields ("id"). can compile , load class easily. can see compiled class in directory, , when open in eclipse, can see member field has annotation. when try read annotation, using field.getannotations(), following things happen:

1) when run application stand alone, can annotation "key".

2) when run application on tomcat server, getannotations() method returns empty list. there no "key" annotation.

just note have retentionpolicy.runtime in key class. how can annotation when run on server ? possible things for, resolve issue ?

ps : code

@override     public class<?> createindexclass(indexdefinationdata createindex) {         indexdtocreator creator = new indexdtocreator();         indexgenerationresult result = creator.process(createindex); // creates source file         class<?> clazz = (activateindexclass(result)); //compiles , loads class          try {             java.lang.reflect.field x = clazz.getdeclaredfield("id");             (annotation y : x.getannotations()) {                 system.out.println(y.annotationtype() + " " + y.tostring());             }             system.out.println(x.isannotationpresent(key.class));         } catch (nosuchfieldexception e) {             // todo auto-generated catch block             e.printstacktrace();         } catch (securityexception e) {             // todo auto-generated catch block             e.printstacktrace();         }         return clazz;     } 

//class loader

private class<?> loadclass(string foldername, string fqcn) throws malformedurlexception, classnotfoundexception {         final url url = paths.get(foldername).touri().tourl();         final classloader loader = new urlclassloader(new url[] { url });         return loader.loadclass(fqcn);     } 


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -