Andrqxa
Andrqxa

Reputation: 87

Yet another problem with JAXB on JDK-11. Now with tycho-compiler plugin

I decided to migrate our legacy project from jdk7 to jdk11 and can't resolve problem with jaxb. We have a multi-module maven project. Here is a part of the parent pom

<?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/maven-v4_0_0.xsd">
  
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.XXX.core.build</groupId>
  <artifactId>parent</artifactId>
  <version>2.1.2</version>
  <packaging>pom</packaging>
  <name>Core Build</name>
  
  <prerequisites>
    <maven>3.6</maven>
  </prerequisites>

  <modules>


    <!-- <module>./targetdefs</module> -->    
    <module>../com.XXX.core</module>
    ....more modules

  </modules>
  
   
  <properties>
    
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jdk-version>11</jdk-version>    
    <!-- Plugins tycho version -->
    <tycho.version>1.7.0</tycho.version>
    
    
    <javax.activation.version>1.2.0</javax.activation.version>
    <jaxb.api.version>2.3.0</jaxb.api.version>
    
  </properties>  
  
  <dependencyManagement>
    <dependencies>  
    <!-- API -->
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>2.3.3</version>
        <!--<scope>compile</scope>-->
    </dependency>
    
    <!--Runtime--> 
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.3</version>
        <scope>runtime</scope>
    </dependency>
    
    </dependencies> 
  </dependencyManagement>

  <build>
    <sourceDirectory>${basedir}/src</sourceDirectory>
    <testSourceDirectory>${basedir}/src</testSourceDirectory>    
    <plugins>
      <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-compiler-plugin</artifactId>
        <version>${tycho.version}</version>
        <configuration>
          <source>${jdk-version}</source>
          <target>${jdk-version}</target> 
        </configuration>
      </plugin>
  </build>    
  
</project>

And here is the child pom

<?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/maven-v4_0_0.xsd">
  
  <modelVersion>4.0.0</modelVersion>
  
  <parent>    
    <groupId>com.XXX.core.build</groupId>
    <artifactId>parent</artifactId>
    <version>2.1.2</version>
    <relativePath>../com.XXX.core.build/pom.xml</relativePath>  
  </parent>
  
  <artifactId>com.XXX.core</artifactId> 
  <packaging>eclipse-plugin</packaging>
  <name>Core</name>
  
    
  <dependencies>
    <!-- API -->
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>2.3.3</version>
        <!--<scope>compile</scope>-->
    </dependency>
    
    <!--Runtime--> 
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.3</version>
        <scope>runtime</scope>
    </dependency>
  </dependencies>
  
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
      </plugin>
    </plugins>
    <resources>
      <resource>
        <directory>${basedir}</directory>
        <filtering>true</filtering>
        <includes>
          <include>**/version.properties</include>
        </includes>
      </resource>
    </resources>
  </build>
  
</project>

But after trying to execute mvm clean install on child pom I'm getting

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.7.0:compile (default-compile) on project com.XXX.core: Compilation failure: Compilation failure:
[ERROR] PATH\core\util\stax\StaxIterator.java:[17]
[ERROR]         import javax.xml.bind.JAXBContext;
[ERROR]                ^^^^^^^^^^^^^^
[ERROR] The import javax.xml.bind cannot be resolved

Although Netbeans added jakarta.xml.bind-api and jaxb-impl as libraries and there are no any error in file StaxIterator.java

I followed this post How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9

How could I resolve problem in such situation - I tried all the possibility from StackOverflow :(

Upvotes: 0

Views: 1200

Answers (1)

Andrqxa
Andrqxa

Reputation: 87

The problem was SOLVED There is no need to add dependencies to maven at all. The root of the issue (in my case) was in file META-INF/MANIFEST.MF I've just added javax.xml.bind to the "Import-Package:" section

...
Import-Package: javax.persistence,
 javax.xml.bind,
 org.apache.commons.beanutils,
 org.osgi.framework;version="1.6.0",
 org.osgi.service.event;version="1.3.0",
 org.slf4j;version="1.7.30"

Upvotes: 0

Related Questions