I'm dealing with an older application that we recently updated from Java 8 to Java 11. In one part of the application, I have several XML files (XSDs) that are converted into Java classes using the Jaxb2 Maven plugin. It worked fine with Java 8, but after switching to Java 11, I encountered an error: 'code too large'.
I know that in Java, a method or function can't exceed 65536 bytes in size. But it's puzzling why it worked with Java 8 and not with Java 11. I've spent two weeks on this issue, and I still don't understand why it worked before.
The problem is, I can't split the code into smaller parts because of some limitations. I tried using another plugin called Castor, hoping it would solve the issue, but it also ran into the same problem.
I experimented with different versions of both plugins, but none of them worked with Java 11. The rest of the application runs smoothly with Java 11. It's only when I change the Java version in the Maven plugin that I encounter this compilation error.
Please help to get me out of this issue as I already have spent time alot. Thanks in advance.
<configuration>
<release>8</release> <!-- working fine -->
<release>11</release> <!-- problem -->
<!--<compilerArgs><arg>-J-Xmx512m</arg></compilerArgs>-->
</configuration>
This is the code for plugin Jaxb2 (Dependencies I added and plugin)
pom.xml
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>4.0.0</version>
<scope>runtime</scope>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<!--<compilerArgs><arg>-J-Xmx512m</arg></compilerArgs>-->
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- The schema directory or xsd files. -->
<!--<arguments>
<arg>-XautoNameResolution</arg>
</arguments>-->
<sources>
<source>src/main/resources/xsds</source>
</sources>
<xjbSources>
<xjbSource>src/main/resources/xsds/bindings.xjb</xjbSource>
</xjbSources>
<!-- The package in which the source files will be generated. -->
<packageName>com.example.java</packageName>
<!-- The working directory to create the generated java source files. -->
<outputDirectory>${project.build.directory}/generated-sources/jaxb/</outputDirectory>
</configuration>
</plugin>
bindings.jxb
<?xml version="1.0"?>
<jaxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jaxb:extensionBindingPrefixes="xjc"
version="3.0">
<jaxb:bindings schemaLocation="../xml/afd/code.xsd" node="/xs:schema">
<jaxb:globalBindings typesafeEnumMemberName="generateName" typesafeEnumMaxMembers="4300">
<jaxb:serializable uid="1"/>
</jaxb:globalBindings>
</jaxb:bindings>
</jaxb:bindings>
This is the configuration, I did for Castor plugin
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!--<version>3.8.1</version>-->
<configuration>
<release>11</release>
<!--<compilerArgs><arg>-J-Xmx512m</arg></compilerArgs>-->
</configuration>
</plugin>
<!-- JAXB xjc plugin that invokes the xjc compiler to compile XML schema into Java classes.-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>generate-main-java-classes</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/xsds</schemaDirectory>
<!--<bindingfile>src/main/resources/xsds/binding.xml</bindingfile>-->
<packaging>com.example</packaging>
<generateImportedSchemas>true</generateImportedSchemas>
<descriptors>false</descriptors>
<generateMappings>true</generateMappings>
<dest>${project.build.directory}/generated-sources/jaxb/</dest>
</configuration>
</execution>
</executions>
</plugin>
I have simpletype in xsd as follow
<xs:simpleType name="CODES" >
<!--<xs:annotation><xs:appinfo>
<jaxb:globalBindings typesafeEnumMaxMembers="0" />
</xs:appinfo></xs:annotation>-->
<xs:restriction base="fm:AN__5">
<xs:enumeration value="1000"/>
<xs:enumeration value="1001"/>
<xs:enumeration value="1002"/>
<xs:enumeration value="1003"/>
.... up to more than 4000 lines
</xs:restriction>
</xs:simpleType>