Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jaxb.properties file from java package not included in Maven built .war

Tags:

java

maven

jaxb

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!

like image 222
Martin Spa Avatar asked Nov 24 '11 09:11

Martin Spa


3 Answers

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.

like image 131
Matthew Fellows Avatar answered Oct 28 '22 01:10

Matthew Fellows


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.

like image 13
oers Avatar answered Oct 28 '22 01:10

oers


add to your pom.xml

    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/jaxb.properties</include>
            </includes>
        </resource>         
    </resources>
like image 1
Striker Avatar answered Oct 28 '22 00:10

Striker