JAXB编译jdk 20(> = 11)

问题描述 投票:0回答:0

我正在尝试将我的项目迁移到 JDK 20(我是 java 模块化的新手) 该项目非常简单,它是一个具有 Google Kml 类的 JAXB 编译实用程序。 我将 module-info.java 创建为:

module View {
   requires java.base;
   requires java.xml.bind;
}

pom.xml中的maven编译器如下:

<?xml version="1.0" encoding="UTF-8"?><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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>savino.prove</groupId>
<artifactId>View</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>20</maven.compiler.source>
    <maven.compiler.target>20</maven.compiler.target>
    <exec.mainClass>savino.prove.view.View</exec.mainClass>
</properties>
<dependencies>
   
    <!-- JAXB for JDK -->
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>3.0.2</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>3.0.2</version>
    </dependency>
    
    
    
    <dependency>
        <groupId>CSGXml</groupId>
        <artifactId>XmlModels</artifactId>
        <version>1.0</version>
        <type>jar</type>
    </dependency>
</dependencies>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    
                    <release>20</release>
                    <compilerArgs>
                        <arg>--add-modules</arg>
                        <arg>java.xml.bind</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>    
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.5.0</version>
            <executions>
                <execution>
                    <id>xjc-schema1</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <!--target>3.0</target-->
                        <xjbSources>
                            <xjbSource>src/main/bindings.xjb</xjbSource>
                        </xjbSources>
                        <!--outputDirectory>${basedir}/out</outputDirectory-->
                        <sources>
                            <source>
                                src/main/xsd/ogckml22.xsd
                            </source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
            
        </plugin>
</plugins>
</build>

问题是:

  1. 在 module-info.java '需要 java.xml.bind' 报告消息'找不到模块'
  2. 在生成的类中,所有涉及“javax.xml.*”包的导入都会报告消息“包 javax.xml.bind 不可见” (包javax.xml.bind在未命名模块中声明,但模块View不读取它)'

当然在项目依赖项中我可以看到 jaxb-api-2.3.1.jar

那我哪里做错了?

现在,只是清理 pom,避免与版本 3.0.2 的依赖。现在我只是:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>savino.prove</groupId>
<artifactId>View</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>20</maven.compiler.source>
    <maven.compiler.target>20</maven.compiler.target>
    <exec.mainClass>savino.prove.view.View</exec.mainClass>
</properties>
<dependencies>
   
    <!-- JAXB for JDK -->
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
        <type>jar</type>
    </dependency>
    <!--
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>3.0.2</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>3.0.2</version>
    </dependency>
    -->
    
    <!--
    <dependency>
        <groupId>CSGXml</groupId>
        <artifactId>XmlModels</artifactId>
        <version>1.0</version>
        <type>jar</type>
    </dependency>
    -->
</dependencies>
<build>
    
        <plugins>  
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>20</source>
                    <target>20</target>
                    <release>20</release>
                    <compilerArgs>
                        <arg>--add-modules</arg>
                        <arg>java.xml.bind</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        
    
      
</plugins>
</build>

现在我只有 jaxb-api 2.3.1 (包含 javax.xml.bind 模块)的依赖项和一个简单的类,该类需要 javax.xml.bind 中的一些类,但这里仍然存在两个问题!

java jaxb modularity
© www.soinside.com 2019 - 2024. All rights reserved.