JAXB compile jdk 20 (>= 11)

527 Views Asked by At

I am trying to migrate my project to JDK 20 ( I am new to java modularization) The project is very simple , it is a JAXB compile utility to have Google Kml Classes. I created the module-info.java as :

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

And the maven compiler in pom.xml is as :

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

The problems are :

  1. in module-info.java 'requires java.xml.bind' report message 'module not found'
  2. in generated classes all import that involves 'javax.xml.*' package report message 'package javax.xml.bind is not visible (package javax.xml.bind is declared in the unnamed module, but module View does not read it)'

ofcourse in project dependencies I can see the jaxb-api-2.3.1.jar

then where I am doing wrong ?

Now , just a cleaning of pom avoiding dependencies with version 3.0.2.Now I am just:

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

Now I have just dependency from jaxb-api 2.3.1 (containing javax.xml.bind module) and a simple class that need some classes from javax.xml.bind but stil two problem are here!

0

There are 0 best solutions below