gpt4 book ai didi

java - 为什么 Maven 不打包我的 hibernate 映射文件?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:41:12 24 4
gpt4 key购买 nike

我正在为 Java 网络应用程序使用 Maven 2 和 Hibernate。

我有一个 Hibernate 映射文件,Domain.hbm.xml 在同一个源文件夹中,有几个域类。

如果我运行 mvn clean package,我发现这个文件没有复制到目标文件夹的 war 文件中。

但是,如果我只执行 mvn clean 然后转到 eclipse 并从“项目”菜单中选择“清理”,文件将发送到目标中的适当位置。然后我可以执行 mvn package 来成功打包一个可以访问数据库的 war 文件。

这是一个pom设置吗?怎么回事?

最佳答案

If I run mvn clean package I find that this file is not copied into the war file in the target folder.

那么映射文件很可能不在默认资源目录(src/main/resources),而是在源目录(src/main/java)和Maven默认情况下不会将它们复制到构建输出目录。

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.

在 Eclipse 下,我的猜测是来自源目录的文件被复制到构建输出目录,包括应用程序资源文件。因此,当您在 Eclipse 清理步骤之后运行 package 时,这会以某种方式“欺骗”Maven。但这其实并不重要,master 就是 Maven,其他的都无关紧要。

要修复它,请将您的映射文件移动到 src/main/resources。或者将它们保存在 src/main/java 中并将源目录声明为“额外”资源目录:

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>

有些人这样做,我更喜欢使用单独的目录。

关于java - 为什么 Maven 不打包我的 hibernate 映射文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3587931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com