2 Replies Latest reply: Jul 28, 2009 7:37 AM by 843793 RSS

    Build problem with Maven

    843793
      Hi.

      I have upgraded from 1.5 APT to the 1.6 method of doing compile time annotations, and I am runing into a problem trying to build a jar containing my annotations processor.

      I get the error from maven (mvn package)

      [INFO] Compilation failure
      error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider annotations.processing.processors.CodeAnnotationProcessor not found

      I have the following directory structure

      src
      --main
      ----java
      ------annotations
      --------processing
      ----------processors
      ------------CodeAnnotationProcessor.java
      ----------annotations
      ------------CodeAnnotation.java
      ----resources
      ------META-INF
      --------service
      ----------javax.annotation.processing.Processor

      I build this with the following with maven
      <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/maven-v4_0_0.xsd">
      
          <modelVersion>4.0.0</modelVersion>
          <groupId>mygroup</groupId>
          <artifactId>annotations-processor</artifactId>
          <packaging>jar</packaging>
          <version>1.0.0</version>
          <name>annotations-processor</name>
          <url>http://maven.apache.org</url>
      
          <dependencies>
              <dependency>
                  <groupId>com.sun</groupId>
                  <artifactId>tools</artifactId>
                  <version>1.4.2</version>
                  <scope>system</scope>
                  <systemPath>C:/Java/jdk1.6.0_10/lib/tools.jar</systemPath>
              </dependency>
          </dependencies>
      
          <build>
              <plugins>
                  <plugin>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <configuration>
                          <source>1.6</source>
                          <target>1.6</target>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
      </project>
      The javax.annotation.processing.Processor file contains
      annotations.processing.processors.CodeAnnotationProcessor
      Any my
      package annotations.processing.processors;
      
      import javax.annotation.processing.AbstractProcessor;
      import javax.annotation.processing.RoundEnvironment;
      import javax.annotation.processing.SupportedSourceVersion;
      import javax.annotation.processing.SupportedAnnotationTypes;
      import javax.lang.model.element.TypeElement;
      import javax.lang.model.SourceVersion;
      import java.util.Set;
      
      @SupportedAnnotationTypes(
              "annotations.processing.annotations.CodeAnnotation")
      @SupportedSourceVersion(SourceVersion.RELEASE_6)
      public class CodeAnnotationProcessor extends AbstractProcessor {
      
          public boolean process(Set<? extends TypeElement> annotations,
                                 RoundEnvironment roundEnv) {
              return true;
          }
      }
      And my CodeAnnotation is as follows
      package annotations.processing.annotations;
      
      import java.lang.annotation.Target;
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      
      
      @Target(ElementType.TYPE)
      @Retention(RetentionPolicy.SOURCE)
      public @interface CodeAnnotation {
      }
        • 1. Re: Build problem with Maven
          843793
          Milesy wrote:
          Hi.

          I have upgraded from 1.5 APT to the 1.6 method of doing compile time annotations, and I am runing into a problem trying to build a jar containing my annotations processor.

          I get the error from maven (mvn package)

          [INFO] Compilation failure
          error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider annotations.processing.processors.CodeAnnotationProcessor not found
          For me it worked when I used the settings
          ...
          <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                  <source>1.6</source>
                  <target>1.6</target>
                  <fork>true</fork>
                  <executable>${java.home}/../bin/javac</executable>
                  <compilerArgument>-proc:none</compilerArgument>
                </configuration>
              </plugin>
          </plugins>
          ...
          Forking the compiler is perhaps not the best option, but its just for the annotation processor.
          • 2. Re: Build problem with Maven
            843793
            Ah I see what you are doing there, Thank you.

            Chris