简体   繁体   English

Maven 无法使用 OpenJDK 11 找到 jaxb-api,即使它存在于存储库中

[英]Maven is not able to find jaxb-api with OpenJDK 11 even though its present in the repository

I have a machine having Windows OS, it is used to build few WAR Projects.我有一台装有 Windows 操作系统的机器,它用于构建几个 WAR 项目。 It has Java 8 installed on it.安装Java 8 I am using Maven 3.2.5 to build these WAR Projects.我正在使用Maven 3.2.5来构建这些 WAR 项目。 Everything is working fine.一切正常。 But as Java 8 will be a problem in future due to its end of free updates I thought of upgrading to OpenJDK 11.但是由于 Java 8 将停止免费更新,因此将来会成为一个问题,我想升级到 OpenJDK 11。

I downloaded OpenJDK 11 but did not install it as I just wanted to try this for 1 of the project to start.我下载了 OpenJDK 11,但没有安装它,因为我只是想尝试启动项目 1。 I picked up one of the WAR Project to check if OpenJDK 11 works.我选择了其中一个 WAR 项目来检查 OpenJDK 11 是否有效。 This project is created using JHipster and Spring Boot.这个项目是使用 JHipster 和 Spring Boot 创建的。 I changed the pom.xml for this project to use spring-boot.version to 2.1.2 and java.verion to 11 and also put the jaxb-api, jaxb-impl, jaxb-runtime and javax.activation enteries(as shown below) to avoid jaxb related dependency errors in Java 11.我把这个项目的 pom.xml 改成使用spring-boot.version to 2.1.2java.verion to 11并且还把jaxb-api, jaxb-impl, jaxb-runtimejavax.activation (如下图) ) 以避免 Java 11 中与 jaxb 相关的依赖错误。

In windows command prompt, I set the JAVA_HOME and PATH variables to OpenJDK11 and then I fire the mvn clean compile package command.在 Windows 命令提示符下,我将JAVA_HOMEPATH变量设置为 OpenJDK11,然后触发mvn clean compile package命令。 As expected all jaxb related dependencies are downloaded in the maven repository but still maven is throwing error NoClassDefFoundError: javax/xml/bind/JAXBException while jaxb-api jar is still there in Maven repository.正如预期的那样,所有与 jaxb 相关的依赖项都已下载到 maven 存储库中,但 maven 仍然抛出错误NoClassDefFoundError: javax/xml/bind/JAXBException而 jaxb-api jar 仍在 Maven 存储库中。 I tried to fire the command again but no luck.我试图再次启动命令,但没有成功。

Can anyone please guide me about the possible root cause or any workaround.任何人都可以指导我了解可能的根本原因或任何解决方法。

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>

原因可能是java9之后的modules,所以你应该创建一个module-info.java文件,更多细节参考相关文档。

Apparently only jars upgrade of various components are needed to support JDK11 in Java projects written using Java8.显然,在使用 Java8 编写的 Java 项目中,只需对各种组件进行 jars 升级即可支持 JDK11。 Module support is not needed until you want to create modular projects in the product and Import/Export of module is needed.除非您想在产品中创建模块化项目并且需要模块的导入/导出,否则不需要模块支持。

I have upgraded the Javaassist Jar as well along with the ones mentioned in question and everything started working fine after it.我已经升级了 Javaassist Jar 以及提到的那些,之后一切都开始正常工作。

<javassist.version>3.24.1-GA</javassist.version>

and as mentioned in question itself正如问题本身所提到的

        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.2</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>javax.activation-api</artifactId>
            <version>1.2.0</version>
        </dependency>

I have the same problem, I use spring-boot and java 11. This help me.我有同样的问题,我使用 spring-boot 和 java 11。这对我有帮助。

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
</dependency>

I got this working with the following POM我使用以下 POM 进行了此操作

<properties>
    <maven-jaxb2-plugin.version>0.14.0</maven-jaxb2-plugin.version>
</properties>

// //

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.4.0-b180830.0359</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.activation/activation -->
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.0-b170127.1453</version>
    </dependency>
</dependencies>

// //

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>${maven-jaxb2-plugin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
                <schemaIncludes>
                    <include>*.wsdl</include>
                </schemaIncludes>
            </configuration>
        </plugin>
    </plugins>
</build>

Add the code below into the start-class(such as SpringBootApplication):在start-class(如SpringBootApplication)中加入如下代码:

@Bean
public TomcatServletWebServerFactory tomcatFactory() {
    return new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
        }
    };
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven 插件失败,缺少 class javax/xml/bind/JAXBException,即使在添加 jaxb-core、jaxb-api、jaxb-impl 依赖项之后也是如此 - Maven Plugin fails with missing class javax/xml/bind/JAXBException even after adding jaxb-core, jaxb-api, jaxb-impl dependencies Confluent Maven 存储库不适用于 OpenJDK11 - Confluent Maven repository not working with OpenJDK11 在中央找不到工件 sun-jaxb:jaxb-api:jar:2.2 - Could not find artifact sun-jaxb:jaxb-api:jar:2.2 in central Docker:由于未找到 JAXB-API,Jenkins-jdk11 无法连接到 Nexus - Docker: Jenkins-jdk11 fails to connect to Nexus due to JAXB-API has not been found Java 11:在模块路径或类路径上未找到 JAXB-API 的实现 - Java 11: Implementation of JAXB-API has not been found on module path or classpath parallelStream() 使用 JAXB-API 导致 ClassNotFoundException - parallelStream() causing ClassNotFoundException with JAXB-API 我的 Eclipse 插件没有找到 JAXB-API 的实现 - Implementation of JAXB-API has not been found by my Eclipse plugin 在模块路径或类路径上找不到 JAXB-API - JAXB-API has not been found on module path or classpath Maven 编译 GWT 和 OpenJDK 11 - Maven Compile GWT & OpenJDK 11 Tomcat 9 无法从 OpenJDK 11 启动 - Tomcat 9 not able to start with OpenJDK 11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM