If I run mvn clean package I find that this file is not copied into the war file in the target folder.
Then the mapping files are probably not in the default resource directory (src/main/resources
) but in the source directory (src/main/java
) and Maven won't copy them to the build output directory by default.
However, if I do only mvn clean and then go to eclipse and select Clean from the Project menu, the file is sent to the appropriate place in the target. I can then do mvn package to sucessfully package a war file that has access to the database.
Under Eclipse, my guess is that files from sources directories get copied to the build output directory, including application resource files. So this somehow "trick" Maven when you run package
after the Eclipse clean step. But this doesn't really matter, the master is Maven, everything else is irrelevant.
To fix it, either move your mapping files to src/main/resources
. Or keep them in src/main/java
and declare the sources directory as an "extra" resource directory:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
Some people do this, I prefer to use separate directories.