当前位置: 首页 > 知识库问答 >
问题:

NetBeans和错误的服务配置文件,或在构建处理器对象时引发的异常

罗兴运
2023-03-14

以下是通过javaCompiler taska进行诊断时出现的错误:

  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

我试图动态编译一个简单的java类从文件,使用JavaCompiler。这个类看起来像:

package web.others;

public class User {

}

我的项目是Maven项目类型

正如你所看到的,康纳廷的班级没什么特别的。我需要的一件事是从这个类中获取一个类对象。但在运行时。我想编译这个动态类并获取类对象。问题是我正在开发Netbeans平台,我想在这个IDE中实现这一点(我开发了一个简单的插件)

要编译并运行im,请使用以下代码:

 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);
 }

我总是从诊断中得到以下错误:

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

任何人都可以帮助这个问题,我将是一个伟大的帮助!

更新:

这里我的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>

共有1个答案

常海
2023-03-14

我也面临着同样的问题。问题是,maven complier插件

这样做的目的是告诉编译器不要自己使用这个处理器。如果你没有它,它会在编译处理器的过程中尝试使用该处理器,而且(很明显)它不会找到它,因为它正在被编译。

(或者至少我是这样理解这件事的,如果我错了,请纠正我)。

 类似资料:
  • 我正在Java写一个简单的自定义注释,遇到了一个问题。下面是我的代码的主要部分。 日志自定义注释。JAVA LogMeCustomAnnotationProcessor。JAVA /src/main/resources/META-INF/services/javax.annotation.processing.处理器 波姆。xml 现在,当我运行时,我得到以下问题 我一定错过了一个简单的技巧。有什

  • 我在AIX服务器上编译java源代码时出错,编码设置为IBM-1047。下面是错误, [INFO]2018-04-17 09:21:13,272[main]-编译输出消息错误:构造处理器对象时引发的异常:无效索引 [致命]2018-04-17 09:21:13273[main]-错误:构造处理器对象时引发异常:索引无效 如果我删除编码变量,并使用默认编码作为ISO-8859-1编译,我得到下面的错

  • 大家好,我刚刚按照给出的步骤进行操作,以便使用parse4cn1 lib实现推送通知。在发送Android构建时,我收到了此错误构建,我真的不知道下一步该做什么,因为我仔细按照说明进行操作。任何帮助将不胜感激。下面是导致错误的链接.txt文件 https://drive.google.com/open?id=0ByIex_y9vYt5UGpfNS1YdkdLZ0k

  • 我正在将本地netty服务器连接到远程https服务器以代理请求。 下面是我如何创建ssLcontext bean 当我点击我的本地主机时,它应该代理到后端。我得到以下异常。但是,如果SSL关闭并且我连接到远程,这是在不同端口上运行的本地服务器,则工作正常 编辑 添加的日志

  • 我正在处理一个Spring启动应用程序。我尝试处理异常。但我想我这样做的方式有问题,因为它总是抛出内部服务器错误500。 我尝试设置自定义异常类,并且还使用带有@响应状态的响应状态代码。但是不管异常是什么,它只会抛出内部服务器错误。我使用的是intellij,我在异常中给出的消息打印在那里,但响应正文empty.This我想一定是因为它抛出了内部服务器错误。 控制器类 intellij 中的终端打

  • 此代码的输出是 这意味着异常将由<代码>接收器重新引发。下一步(i) 在推送方法和非推送错误反应通道中。为什么?