Maven 2 和 Hibernate
我一整天都在试图解决这个问题。我已经广泛搜索了 SO 和 Google,但似乎找不到适合非常基本的初学者的东西。基本上我是一名实习生,需要设置 Maven,然后设置 Hibernate。我已经安装了 Maven,并且正在按预期运行。但当谈到 Hibernate 时,我只是不知道该怎么做。该文档不是最好的,我找到的唯一教程是如果您想使用 IDE 设置 Hibernate。
这是教程我正在跟踪,它开始假设您已经设置了 Hibernate 环境,几乎没有解释如何实际设置它。
我的问题是
- 如何设置 Hibernate
- 如何使用将 Hibernate 集成到 Maven 中。我尝试按照教程进行操作,但我已经 错误提示缺少依赖项。我将这些 jar 包含在 CLASSPAST 环境变量中,但仍然出现错误。我知道 POM 中引用了依赖项,但我不明白为什么我的会搞砸。
我还读到我需要创建一个为 Hibernate 设置的 Maven 项目,但这永远没有帮助。我尝试使用我认为合适的原型:
mvn archetype:generate
-DgroupId=org.hibernate.tutorials
-DartifactId=hibernate-tutorial
-DarchetypeArtifactId=jpa-maven-archetype
-DarchetypeGroupId=com.rfc.maven.archetypes
尽管没有生成教程中引用的任何文件夹,并且我得到了默认的 App.java 文件,但我不知道如果删除该文件是否重要。
I have been trying to figure this out all day. I've searched SO and Google extensively but I can't seem to find something for very basic beginners. Basically Im an intern where I am required to setup Maven and then setup Hibernate. I have maven setup and is running as it should. But when it comes to Hibernate I am just drawing blanks on what to do. The documentation isn't the best and the only tutorials I find are if you want to setup Hibernate with an IDE.
This is the tutorial I am following and it starts off assuming you have already setup the Hibernate environment with almost no explanation as to how to actually set it up.
My questions are
- How do I setup Hibernate
- How do I use integrate Hibernate into Maven. I try to follow the tutorial but I have
errors saying missing dependencies. I included the jars in my CLASSPAST environment var and I still get the errors. I understand the dependencies are referenced in the POM but I don't get why mine messing up.
Also I read that I need to create a Maven project that is setup for Hibernate but that never helps. I try to use what I think is the appropriate archetype:
mvn archetype:generate
-DgroupId=org.hibernate.tutorials
-DartifactId=hibernate-tutorial
-DarchetypeArtifactId=jpa-maven-archetype
-DarchetypeGroupId=com.rfc.maven.archetypes
Although none of the folders referenced in the tutorial are generated and I get the default App.java file which I don't know if that matters if I delete that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hibernate 对 Maven 不太友好。他们在内部使用另一个构建工具 - 这就是我猜的原因。
要设置基于 Hibernate Maven 的应用程序,请按照 操作您提到的他们的教程并且不使用任何原型。它将为您提供一个与 Maven 集成的真正的 Hibernate 应用程序。
哦,我明白你的困惑来自哪里。本教程不会假设您已经设置了 Hibernate 环境!您唯一需要创建的是以粗体列出的目录 - src/main/java 、 src/main/resources 和 src/main/webapp< /代码>。与
pom.xml
一起,它们将成为Hibernate环境 - 所有Hibernate JAR都将自动下载,一旦您运行诸如mvn package之类的东西,您的项目就会被构建
;-)当然,Hibernate 教程中有一个 BUG(似乎有几年了),在 此论坛帖子。因此,请使用链接中的最后一个(底部)pom.xml。它使用版本
3.6.1
,但从今天起最新的是4.0.0
但我不敢使用它;-) 你可能想使用最新的 3 .xx 虽然是3.6.9
- 只需替换pom.xml
中的版本号Hibernate is not very Maven friendly. They are using another build tool internally - that's why I guess.
To setup a Hibernate Maven-based application please just follow their tutorial that you mentioned and not use any archetypes. It will give you a real Hibernate application integrated with Maven.
Oh, and I see where your confusion is coming from. The tutorial doesn't start off assuming you have already setup the Hibernate environment! The only thing you need to create are the directories listed there in bold -
src/main/java
,src/main/resources
andsrc/main/webapp
. Together with apom.xml
they will become the Hibernate environment - all Hibernate JAR will get downloaded automatically and your project will get built once you run something likemvn package
;-)And of course Hibernate tutorial has a BUG in it (for a couple of years it seems) described in this forum post. So please use the last (at the bottom) pom.xml from the link. It uses version
3.6.1
, but since today the latest is4.0.0
but I wouldn't dare to use it ;-) You may want to use the latest 3.x.x though which is3.6.9
- just replace version numbers inpom.xml