Search code examples
xmljaxbeclipselinkmoxy

Strange "missing an @XmlRootElement annotation" error, only with Maven, works in Eclipse


I wrote code that marshals xml data. Before marshaling the data to output i validate the data the way Blaise Doughan suggests here

Running a simple test in eclipse (marshaling data an validating it) works fine, but as soon i run the test in console (mvn test) i get "missing an @XmlRootElement annotation".

The code is generated by moxy - without this annotation. And my Question is why it works in Eclipse? Or how to get it working also in console? The only explanation i have is that some dependencies are different (probably eclipse uses some internal xml stuff?)

I am aware of the possibility to wrap my root-element in JAXBElement - but for some reason it works in eclipse without annotation and without wrapping.


Solution

  • Blaise is right, the jaxb.properties must be under resource in same folder structure(package) as in src/main/java folders. In my case i have 20 of those files (and jaxb-classes for 20 xsd). To get it working without manually copying add to pom:

    <build>
    ...
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/jaxb.properties</include>
                </includes>
            </resource>
        </resources>
    ...
    </build>
    

    the first "resource" adds the normal resource folder. the 2nd adds src/main/java but includes only all jaxb.properties wherever they are.