I'm on a java/maven project, using the jaxb2 inheritance plugin in order to define parent classes for xjc-generated java classes.
I'm having this xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jaxb:extensionBindingPrefixes="inheritance"
elementFormDefault="qualified"
jaxb:version="2.1">
<xs:element name="input">
<xs:complexType>
<xs:sequence>
<xs:element ref="test.thing"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="test.thing">
<xs:annotation>
<xs:appinfo>
<inheritance:implements>
input.generation.common.IXmlHasListedElementsWithStartTime
</inheritance:implements>
<inheritance:extends>
input.generation.common.XmlAbstractTestThingWithListedElementWithStartTime
</inheritance:extends>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="start.timed.thing" type="start.timed.thing" maxOccurs="unbounded" minOccurs="0">
<xs:annotation>
<xs:appinfo>
<jaxb:property name="startTimedThings"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="start.timed.thing">
<xs:annotation>
<xs:appinfo>
<inheritance:implements>
input.generation.IHasStartTime
</inheritance:implements>
</xs:appinfo>
</xs:annotation>
<xs:attribute name="start" use="optional" type="xs:date"/>
</xs:complexType>
</xs:schema>
It is generating a class XmlTestThing extends XmlAbstractTestThingWithListedElementWithStartTime implements IXmlHasListedElementsWithStartTime.
The ultimate goal is that the interface defines an easy method that gives the right version of XmlTestThing, given the date.
Here's the problem: when I do a mvn clean install on my project, the process fails on compile errors in my IDE (eclipse). The problem is that the generated class XmlTestThing cannot find its abstract parent XmlAbstractTestThingWithListedElementWithStartTime. It has no problems finding the interface.
However, doing a refresh on the project, just shows that in eclipse there is no compile problem reported for XmlTestThing: maven cannot find the import, while eclipse can.
The generated class is in target/generated-test-sources. The interface to be implemented is in src/main/java The class to be extended is in src/test/java.
I've tested this a bit, and found the following:
- if the class to be extended is in src/main/java, then it all functions
- if the class to be extended is in src/test/java, eclipse can find it, but maven reports a compile error because it is not able to find it from target/generated-test-sources.
Apparently maven can find the interface in /src/main/java, but not the parent class in /src/test/java. Or does target/generated-test-sources not have access to src/test/java?
Some more info:
This is the part of pom.xml arranging the test-resources:
<plugin>
<!--
The standard location for generated sources is under target, so that
it falls outside the scope of subversion/git. However, the standard maven
setup doesn't support java sources not under src/main/java or src/test/java.
This plugin lets maven know that the generated sources under target
should also be considered as a source folder for java classes.
In this case it is used for test sources. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<!-- This tells the plugin that generated-sources under target is a source folder. -->
<source>${project.build.directory}/generated-test-sources/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
and this is the pom.xml configuration of class generation:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.15.3</version>
<configuration>
<schemaDirectory>src/test/resources</schemaDirectory>
<generateDirectory>${project.build.directory}/generated-test-sources/java</generateDirectory>
<extension>true</extension>
<strict>false</strict>
<forceRegenerate>true</forceRegenerate>
<args>
<arg>-Xinheritance</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.11.1</version>
</plugin>
</plugins>
</configuration>
<executions>
<execution>
<id>input</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>testInput.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>testInput.xjb</include>
</bindingIncludes>
</configuration>
</execution>
</executions>
</plugin>
This xjb does some prefixing of class names:
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" schemaLocation="testInput.xsd">
<jaxb:schemaBindings>
<jaxb:package name="nl.erasmusmc.mgz.core.input.generated.test"/>
<jaxb:nameXmlTransform>
<!-- Prefix all generated classes with Xml -->
<jaxb:typeName prefix="Xml"/>
<jaxb:elementName prefix="Xml"/>
<jaxb:modelGroupName prefix="Xml"/>
<jaxb:anonymousTypeName prefix="Xml"/>
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxb:bindings>
And this would be an xml input file under test:
<?xml version="1.0" encoding="UTF-8"?>
<input
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="testInput.xsd" >
<test.thing>
<start.timed.thing start="1800-01-01"/>
<start.timed.thing start="1970-01-01"/>
<start.timed.thing start="2000-01-01"/>
</test.thing>
</input>