I'm using Maven 2 and Hibernate for a Java web app.
I have a Hibernate-mapping file, Domain.hbm.xml
in the same source folder with several domain classes.
If I run mvn clean package
I find that this file is not copied into the war file in the target folder.
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.
Is a pom setting for this? What's going on?
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.
Resources other than Java sources you want to end up on the classpath directly (in your case inside /WEB-INF/classes) must go in your src/main/resources directory, not src/main/java.
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