According to the API, when creating a JAR which contains compile time an
Annotation Processor it should follow the following structure.

uk
--foo
----bar
------SomeAnnotationProcessor
META-INF
--services
----javax.annotation.processing.Processor

And the javax.annotation.processing.Processor file contains the following
line

uk.foo.bar.SomeAnnotationProcessor

If a META-INF/services/javax.annotation.processing.Processor is detected on
the class path by the compiler it will try locate the Processor listed
within.

This JAR I can build manually, and then add to the classpath for my other
projects, and anytime a class is compiled which is Annotated by an
Annotation handled by the Processor, the Processor is ran during the actual
compilation process. 

This works brilliant and exactly as intended, however I can not build this
structure with maven.

when I do a "mvn package" I get the following error....

[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

My maven structure is as follows:

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

Where the project includes the Annotation Processor, the Annotation handled
by the processor, and the .Processor file which will be picked up by the 1.6
compiler.

My maven POM looks like

<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>  

Now this fails at COMPILE with "mvn compile" with the above directory
structure.

To me this looks like the
META-INF/services/javax.annotation.processing.Processor is being added to
the classpath during compile. This will then cause the compiler to think I
am wanting to process annotations using the referenced processor and then
looks for it, which it cant, because it does not exist.

Is there a way to just exclude this file from the class path during the
build? Or a "non hack" way of getting the file into the jar at the end
without going through the compile process.

I can build all this manually, or build with Maven and then manually add
just the .Processor in using the jar tool at the end, but this is far from
practical.

I hope my explanation of the problem makes sense.

Many Thanks

Chris


-- 
View this message in context: 
http://www.nabble.com/Problem-building-Jar-for-JDK6-Annotation-Processor.-tp24409779p24409779.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to