I put a jaxb.properties file in the package where my classes are where I use a different JAXB provider (as seen in this link Specifying EclipseLink MOXy as Your JAXB Provider) which I use for unmarshalling.
The following occurs:
When I run the project from Eclipse/STS the unmarshalling works OK, since it reads the jaxb.properties file.
When I build the project with Maven 3 (mvn clean install
), the jaxb.properties file isn't included in the package - therefore those classes can't unmarshall XML files successfully. Then I have to manually put the jaxb.properties file by navigating to the deployed app, entering the package and pasting the file.
Solutions? Thanks!
As oers hinted, your best bet is to use the maven-resources-plugin to achieve this.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/path/to/model/</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources/</directory>
<includes>
<include>jaxb.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Place your jaxb.properties
file in directory
and specify the package location (outputDirectory
) and this will copy the resource prior to packaging.
You should put resources(like jaxb.properties) in src/main/resources
.
I can't find any proof/documentation yet, but I am certain that maven will only compile and copy .java
files from the src
folder.
From the documentation it seems clear, that compile will only compile and not copy anything. Therefore only .java
files under src/main/java will be handled and everything else ignored.
Resources are handled by resources:resources, which is executed automatically. This target copies resources from src/main/resources
.
Compile only compiles files from the src folder. Resource files are not java files and will therefore not be copied/compiled to the output directory.
add to your pom.xml
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/jaxb.properties</include>
</includes>
</resource>
</resources>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With