Search code examples
javamavenjakarta-eejava-10

lookup() Method of javax.annotation.Resource not found when using JDK 10


I do have a JavaEE7 application, that compiles well under Java 8. Now I want to migrate to Java 10 and I have a problem with the maven build inside a single class. Here is the snippet:

import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.inject.Inject;

import org.infinispan.Cache;

@Singleton
public class TestCacheProducer {

    @Resource(lookup="java:jboss/infinispan/testcache")
    private org.infinispan.Cache<Long, byte[]> testcache;

I am using the following versions to compile my sources to java 10:

  • maven (3.5.4)
  • maven-compiler-plugin 3.8.0
  • Java 10 (subversion 2)

with the recommended changes in pom.xml

<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.2</version>
</dependency>

and

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.0</version>
  <configuration>
      <source>10</source>                                                
      <target>10</target>                                                
      <release>10</release>                                              
      <executable>javac10</executable>                                   
      <encoding>UTF-8</encoding>
      <compilerArgs>
         <arg>-proc:none</arg>
         <arg>--add-modules</arg>
         <arg>java.xml.bind</arg>
         <arg>--add-modules</arg>
         <arg>java.xml.ws.annotation</arg>
      </compilerArgs>
  </configuration>
  <dependencies>                                                         
    <dependency>                                                       
        <groupId>org.ow2.asm</groupId>                                 
        <artifactId>asm</artifactId>                                   
        <version>6.2</version>
    </dependency>                                                      
  </dependencies>
</plugin>

Inside eclipse (photon) the correct Interface class can be resolved, but when I use maven via a mvn install, then I get these compiler errors.

error: cannot find symbol
            @Resource(lookup="java:jboss/infinispan/testcache")
                      ^
      symbol:   method lookup()
      location: @interface javax.annotation.Resource

I investigated in this error, but I only found people that used a compiler, or a JavaEE Version reference (below JavaEE 6) where the interface class did not have the "lookup" Method. This is not the case here

my maven version info (mvn -v):

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: C:\Softdev\maven\apache-maven-3.5.4\bin\..
Java version: 10, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-10
Default locale: de_AT, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

I also used mvn dependency:tree -Dverbose to see, if there is any dependency, what references an older implementation. Is there any possibility to see, from which referenced file this compile error comes from?

Thanking you in advance for any hint or help.


Solution

  • thanks for all your help. The Problem was caused by the maven-processor-plugin I had to also add compiler arguments for the JDK 10. (the module named 'java.se.ee' includes all JEE modules and you do not need to include them one by one)

    <plugin>
        <groupId>org.bsc.maven</groupId>
        <artifactId>maven-processor-plugin</artifactId>
        <version>3.3.3</version>
         <executions>
            <execution>
                <id>process</id>
                <goals>
                    <goal>process</goal>
                </goals>
                <phase>generate-sources</phase>
                <configuration>
                    <fork>true</fork>
                    <addCompileSourceRoots>true</addCompileSourceRoots>
                    <compilerArguments>--add-modules=java.se.ee -J--add-modules=java.se.ee</compilerArguments>
                    <outputDirectory>${project.build.directory}/metamodel</outputDirectory>
                    <processors><processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                    </processors>
                </configuration>
            </execution>
        </executions>
        <dependencies>  
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-jpamodelgen</artifactId>
                <version>${hibernate.version}</version>
            </dependency>
        </dependencies>
    </plugin>