开发者

Why is maven not packaging my hibernate-mapping file?

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 seve开发者_JAVA百科ral 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.


I had the same issue. This solved my problem.

<sourceDirectory>src/main/java</sourceDirectory>  
    <resources>
        <resource>
            <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
        </resource>
    </resources>


Facing the same problem as well

Following changes in the pom.xml resolved my problem

<build>
    <finalName>spring-mvc-jquery</finalName>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

For different maven version follow the corresponding version layout.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜