Jakarta ee 检查加载的类在JavaEEWeb应用程序中是否有注释

Jakarta ee 检查加载的类在JavaEEWeb应用程序中是否有注释,jakarta-ee,reflection,annotations,Jakarta Ee,Reflection,Annotations,我写了我的类注释: @Documented @Target(ElementType.METHOD) @Retention(RUNTIME) public @interface CAnnotation { String name(); } 接下来我写了我的lib: public class Customized implements Serializable { @CAnnotation(name="getCustomer") public String getCusto

我写了我的类注释:

@Documented
@Target(ElementType.METHOD)
@Retention(RUNTIME)
public @interface CAnnotation {
   String name();
}
接下来我写了我的lib:

public class Customized implements Serializable {

    @CAnnotation(name="getCustomer")
    public String getCustomer(int id){
        return "ABCABC";
    } 
}
现在我阅读了部署到GlassFish 4.1.1
customized.jar的web应用程序,如下所示:

public void inir(){
    System.out.println("---------------");
    System.out.println("---------------");
    for (Method metoda : getUserClass().getMethods()) {
        System.out.println("---------------"
                + "\n" + metoda.isAnnotationPresent(CAnnotation.class)
                + "\n" + metoda.getName()
        );
        for (Annotation annotation : metoda.getAnnotations()) {
            System.out.println("---------------"
                    + "\n" + annotation
            );
        }
        if (metoda.getAnnotation(CAnnotation.class) instanceof CAnnotation) {
            System.out.println("---------------");
            System.out.println(":" + metoda + " " + metoda.getAnnotation(CAnnotation.class).name());
            System.out.println("---------------");
        }
    }
}


public Class getUserClass() {
    File file = new File("./Customized.jar");
    try {
        JarFile jarFile = new JarFile(file.getPath());
        Enumeration e = jarFile.entries();
        URL[] urls = {new URL("jar:file:" + file.getPath() + "!/")};
        URLClassLoader cl = URLClassLoader.newInstance(urls);
        while (e.hasMoreElements()) {
            JarEntry je = (JarEntry) e.nextElement();
            if (je.isDirectory() || !je.getName().endsWith(".class")) {
                continue;
            }
            String className = je.getName().substring(0, je.getName().length() - 6);
            className = className.replace('/', '.');
            Class c = cl.loadClass(className);
            return c;
        }
        return null;
    } catch (IOException | ClassNotFoundException ex) {
        System.out.println("" + ex);
        return null;
    }

}
在控制台中,我得到以下信息:

Info:   ---------------
Info:   ---------------
Info:   ---------------
false
getCustomer
Info:   ---------------
...
我在桌面应用程序中检查了它,得到了“true”。 那么,web应用程序和桌面应用程序有什么区别呢?在web应用程序中,没有我的注释? 我做错了什么? 我使用JDGUI(Java反编译器)检查了服务器上的一个文件,
customized.jar
有注释。
我没有在
web.xml
faces config.xml

中添加任何内容。您的customized.jar是否随web应用部署?否,first deploye app,next deploye jar。您的customized.jar是否随web应用部署?否,first deploye app,next deploye jar。