Bad service configuration file, or exception thrown while constructing Processor object

后端 未结 4 1776
难免孤独
难免孤独 2021-02-20 06:23

I am writing a simple custom annotation in Java and running into a problem with it. Here is the main parts of my code.

LogMeCustomAnnotation.java

相关标签:
4条回答
  • 2021-02-20 06:30

    Ok. Found the issue. Earlier my pom.xml had the proc:none line commented out. Now that I have got it back in action it is compiling fine. I need to find out exactly what this line does, but the answer to my question is just put the proc:none back in game. This is how the build section of my pom.xml looks now.

    <build>
        <plugins>
            <plugin>
                <!-- Configure the project to use java 8 version. -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <!-- Disable annotation processing for ourselves. -->
                    <compilerArgument>-proc:none</compilerArgument>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    0 讨论(0)
  • 2021-02-20 06:37

    Follow the following steps to resolve this:

    • Edit nbproject/project.properties file
    • Search for javac.processorpath, and change it to:

    javac.processorpath=\ ${javac.classpath}:\ ${libs.eclipselink.classpath}

    0 讨论(0)
  • 2021-02-20 06:46

    The default maven lifecycle runs javac with javax.annotation.processing.Processor file as a part of classpath. This cause compiler to expect a compiled instance of annotation processors listed in the files. But LogMeCustomAnnotationProcessor is not compiled at that moment so compiler raises "Bad service configuration file ..." error. See bug report.

    To solve this issue maven compilation phase can be separated to compile annotation processor at the first place and then compile whole project.

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <configuration>
                            <compilerArgument>-proc:none</compilerArgument>
                            <includes>
                                <include>fun/n/learn/annotation/LogMeCustomAnnotationProcessor.java</include>
                                <!--include dependencies required for LogMeCustomAnnotationProcessor -->
                            </includes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>compile-project</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

    default-compile execution compiles LogMeCustomAnnotationProcessor with disabled annotation processing in order to have successful compilation.
    compile-project compiles whole project with annotaton processing.

    0 讨论(0)
  • 2021-02-20 06:46

    I've encountered this error, in particular

    Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider com.iviz.schemarestriction.processor.SchemaRestrictionCompilationProcessor could not be instantiated
    

    when migrating maven project from JDK 1.8 (1.8.0_201) to OpenJDK 11(11.0.2).

    It was fixed by adding dependency on (2.3.1 was the latest stable version)

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    
    0 讨论(0)
提交回复
热议问题