我遇到了OpenJDK11兼容性问题

时间:2018-11-07 20:58:54

标签: java

运行一个简单的嵌入式tomcat应用程序时遇到问题。该项目在这里:

https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat

我将Tomcat版本更新为8.5.34,并添加了maven编译器插件以将源/目标设置为11。

如果我使用OpenJDK 11运行它:

openjdk版本“ 11.0.1” 2018-10-16
OpenJDK运行时环境(内部版本11.0.1 + 13-suse-lp150.2.6.1-x8664)
OpenJDK 64位服务器VM(内部版本11.0.1 + 13-suse-lp150.2.6.1-x8664,混合模式)

我得到了错误:

 Caused by: java.lang.IllegalAccessError: class  org.apache.catalina.startup.WebAnnotationSet (in unnamed module @0x18eed359) cannot access class javax.annotation.security.DeclareRoles (in module java.annotation) because module java.annotation does not export javax.annotation.security to unnamed module @0x18eed359
        at org.apache.catalina.startup.WebAnnotationSet.loadClassAnnotation(WebAnnotationSet.java:258)
        at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:136)
        at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:69)
        at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:328)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:768)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

如果我使用从Oracle网站上下载的Java SE 11.0.1在同一台计算机上运行它,它将按预期运行。 Oracle Java信息是:

java版本“ 11.0.1” 2018-10-16 LTS
Java(TM)SE运行时环境18.9(内部版本11.0.1 + 13-LTS)
Java HotSpot(TM)64位服务器VM 18.9(内部版本11.0.1 + 13-LTS,混合模式)

完整的pom.xml文件为:

<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>com.heroku.sample</groupId>
  <artifactId>embeddedTomcatSample</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>embeddedTomcatSample Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
    <tomcat.version>8.5.34</tomcat.version>
  </properties>
  <dependencies>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jasper</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jasper-el</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jsp-api</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>embeddedTomcatSample</finalName>
    <plugins>
        <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>2.0.0</version>
            <configuration>
                <assembleDirectory>target</assembleDirectory>
                <programs>
                    <program>
                        <mainClass>launch.Main</mainClass>
                        <name>webapp</name>
                    </program>
                </programs>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>assemble</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>
</project>

任何人都可以帮助我了解发生了什么事吗?

0 个答案:

没有答案