开发者

Issue while dynamically compiling jSF2 managed bean class (Using java compiler)

i am getting below exception while compiling manually generated managed managed bean java files(JSF2 with annotations),

error: Class names, 开发者_Go百科'javax.faces.bean.ManagedBean,javax.faces.bean.SessionScoped,javax.faces.bean.ManagedProperty', are only accepted if annotation processing is explicitly requested. 

Below is my code.

    List<String> options = new ArrayList<String>();
    options.add("-classpath");
    options.add(servletContextPath + "WEB-INF\\lib");
    options.add("-d");
    options.add(servletContextPath + "WEB-INF\\classes");
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileMan = compiler.getStandardFileManager(null,
            null, null);
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
    Iterable<? extends JavaFileObject> fileObjs = fileMan
            .getJavaFileObjectsFromStrings(Arrays.asList(javaFileName));
    List<String> annotationClassesToCompile = new ArrayList<String>();
    annotationClassesToCompile.add(ManagedBean.class.getName());
    annotationClassesToCompile.add(SessionScoped.class.getName());
    annotationClassesToCompile.add(ManagedProperty.class.getName());
    CompilationTask task = compiler.getTask(null, fileMan, diagnostics,
            options, annotationClassesToCompile, fileObjs);*/
    final Boolean result = task.call();
    System.out.println(result.toString() + diagnostics);
    for (Diagnostic diag : diagnostics.getDiagnostics()) {
        System.out.println(diag.getMessage(Locale.ENGLISH));
    }


The error message error: Class names, 'X', are only accepted if annotation processing is explicitly requested. is displayed when the extension is incorrect for the supplied class to be compiled. There ought to be a .java suffix for all source files that are compiled via the Java Tools API.

Although the StandardJavaFileManager API documentation indicates that regular files may be supplied, this appears to be currently restricted to files with the .java extension, arising out of the fix for bug 6422327 in the Sun Bug DB.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜