Java — debug the annotation processor in Eclipse

I'm writing a simple annotation processor and trying to debug using eclipse I created a new project for annotation processor and configured javax. Inf under meta - inf as needed annotation. processing. Processor and process comments

Then I added some more code and tried debugging, but never stopped the execution of the breakpoint added in the annotation processor I'm compiling with ant, and I'm using the following ant options

export ANT_ OPTS =“ – Xdebug -Xrunjdwp:transport = dt_socket,server = y,suspend = y,address = 8000”

After triggering the ant build, I will create a remote debugging configuration and the debugger will start working normally Ant build also started successfully However, execution never stops at any breakpoint added to the annotation handler

Solution

This is a newly encountered problem, and the Eclipse Plug-in solution seems too troublesome for me I found that using javax tools. Java compiler is a simpler solution to call the compilation process Using the following code, you can right-click > debug as > jenit to test in eclipse and debug the annotation processor directly from there

@Test
   public void runAnnoationProcessor() throws Exception {
      String source = "my.project/src";

      Iterable<JavaFileObject> files = getSourceFiles(source);

      JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

      CompilationTask task = compiler.getTask(new PrintWriter(System.out),null,files);
      task.setProcessors(Arrays.asList(new MyAnnotationProcessorClass()));

      task.call();
   }

   private Iterable<JavaFileObject> getSourceFiles(String p_path) throws Exception {
     JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
     StandardJavaFileManager files = compiler.getStandardFileManager(null,null);

     files.setLocation(StandardLocation.soURCE_PATH,Arrays.asList(new File(p_path)));

     Set<Kind> fileKinds = Collections.singleton(Kind.soURCE);
     return files.list(StandardLocation.soURCE_PATH,"",fileKinds,true);
   }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>