Netbeans and Bad Service, or an exception thrown while building a Processor object

Here is the error arising from the javaCompiler taska diagnostic test:

Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider org.netbeans.modules.openide.modules.PatchedPublicProcessor not a subtype 

I am trying to dynamically compile a simple Java class from a file using JavaCompiler. This class is as follows:

 package web.others; public class User { } 

My project - Maven project project

since you see that the conatins class is nothing special. The only thing I need is to get the class object from this class. But at runtime. I would like to compile a dynamic class and get a class object. The problem is that I am working on Netbeans Plaform and I want to do this in this IDE (I developed a simple plugin)

Compile and run im using the following code:

  JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); Iterable<? extends JavaFileObject> compilationUnits = Arrays.asList(file); JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null,null,compilationUnits); boolean success = task.call(); try { fileManager.close(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } System.out.println("Success: " + success); if (!success) { List<Diagnostic<? extends JavaFileObject>> dia = diagnostics.getDiagnostics(); System.out.println("Diagnostic: " + dia); } 

And always I get the following error from the diagnosis:

 error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider org.netbeans.modules.openide.modules.PatchedPublicProcessor not a subtype 

Anyone can help with this problem, I will be grateful for the help!

UPDATE:

here is my pom.xml:

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany</groupId> <artifactId>mavenproject2</artifactId> <version>1.0-SNAPSHOT</version> <packaging>nbm</packaging> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>nbm-maven-plugin</artifactId> <version>3.13</version> <extensions>true</extensions> <configuration> <publicPackages> <publicPackage>org.netbeans.modules</publicPackage> </publicPackages> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <useDefaultManifestFile>true</useDefaultManifestFile> <archive> <manifest> <addClasspath>true</addClasspath> </manifest> </archive> </configuration> </plugin> </plugins> </build> <repositories> <repository> <id>netbeans</id> <name>Repository hosting NetBeans modules</name> <url>http://bits.netbeans.org/nexus/content/groups/netbeans</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>unknown-jars-temp-repo</id> <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name> <url>file:${project.basedir}/lib</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-core-ide</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-util</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-awt</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-nodes</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-filesystems</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-loaders</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-windows</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-util-lookup</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-io</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-explorer</artifactId> <version>RELEASE80</version> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-dialogs</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-text</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-modules</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-projectuiapi</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-settings</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-projectapi</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-db</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-editor-lib2</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-editor-lib</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-editor-mimelookup</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-parsing-api</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-editor-indent</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-api-java-classpath</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-java-source</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-libs-javacapi</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-java-project</artifactId> <version>RELEASE80</version> <type>jar</type> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.3.6.Final</version> <type>jar</type> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.3.1.Final</version> <type>jar</type> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-envers</artifactId> <version>4.3.6.Final</version> <type>jar</type> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>4.3.6.Final</version> <type>jar</type> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-proxool</artifactId> <version>4.3.6.Final</version> <type>jar</type> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-infinispan</artifactId> <version>4.3.6.Final</version> <type>jar</type> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId> <version>4.3.6.Final</version> <type>jar</type> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>5.1.3.Final</version> <type>jar</type> </dependency> <dependency> <groupId>unknown.binary</groupId> <artifactId>postgresql-9.2-1002.jdbc4</artifactId> <version>SNAPSHOT</version> </dependency> <dependency> <groupId>org.jboss.logging</groupId> <artifactId>jboss-logging</artifactId> <version>3.1.3.GA</version> <type>jar</type> </dependency> <dependency> <groupId>org.hibernate.common</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>4.0.5.Final</version> <type>jar</type> </dependency> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.18.1-GA</version> <type>jar</type> </dependency> <dependency> <groupId>com.sun.codemodel</groupId> <artifactId>codemodel</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.0.5.RELEASE</version> <type>jar</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.0.5.RELEASE</version> <type>jar</type> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> <type>jar</type> </dependency> <dependency> <groupId>unknown.binary</groupId> <artifactId>postgresql-9.3-1102.jdbc4</artifactId> <version>SNAPSHOT</version> </dependency> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId> <version>2.5.1</version> </dependency> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId> <version>2.5.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> <version>0.9.9-RC1</version> </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> </project> 
+6
source share
1 answer

I faced the same problem. The problem was that this line was missing in the maven-complier-plugin <configuration> :

<compilerArgument>-proc:none</compilerArgument>

The purpose of this is to tell the compiler not to use this processor for himself. If you do not have it, it will try to use this processor during compilation of the processor and (as is obvious), it will not find it from the moment of its compilation.

(or, at least, as I understand it, please correct me if I am wrong).

+4
source

Source: https://habr.com/ru/post/977919/


All Articles