我应该在 pom.xml 中编写存储库吗?
我是 Maven 新手。如果我使用 Maven 启动新项目,我是否应该知道任何存储库 URL 才能使其正常工作?
例如,这个 Hibernate 教程 http://docs.jboss.org/hibernate/ core/3.3/reference/en/html/tutorial.html 说明如何使用 pom.xml 文本创建示例项目。但这个 pom.xml 不包含任何存储库。
所以,我的 m2eclipse 插件说,例如 Project build error: 'dependency.dependency.version' for org.hibernate:hibernate-core:jar is Missing.
,对于 pom.xml 中的所有依赖项标记
是这是因为存储库缺失?
在哪里可以知道存储库 URL?有一个大的存储库吗?为什么默认情况下不包含它?
更新1 这里说,Maven默认应该使用“中央”存储库:http://maven。 apache.org/guides/introduction/introduction-to-repositories.html
我在那里搜索了 hibernate-code 工件并找到了它。所以,这个工件位于中央存储库中。我的行家说找不到依赖项。因此它不使用它的中央存储库。为什么?
I am new to Maven. If I start new project with Maven, should I know any repository URLs for it to work?
For example, this Hibernate tutorial http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html says about how to create a sample project with pom.xml text. But this pom.xml does not contain any repositories.
So, my m2eclipse plugin says, for example Project build error: 'dependencies.dependency.version' for org.hibernate:hibernate-core:jar is missing.
, for all dependency tag in pom.xml
Is this because of repositories absence?
Where to know repositories URLs? Is there one big repository? Why doesn't it included by default?
UPDATE 1
It is said here, that Maven should use "central" repository by default: http://maven.apache.org/guides/introduction/introduction-to-repositories.html
I have searched there for hibernate-code artifact and found it. So, this artifact IS in central repository. By my maven says dependency not found. Hence it doesn't use it's central repository. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然您的 Hibernate 依赖项缺少
标记:请注意,您不必指定先前在
。旧答案:
每个构建脚本(不仅是 Maven)应该是可重复的并且独立于环境。 标准 pom.xml (称为 super pom),每个
pom.xml
都继承自它,已经定义了主 Maven 中央存储库:您不必定义此存储库,也不必定义任何其他存储库,如果你所有的依赖项都是 那里。另一方面,如果您正在使用某些外部存储库,则必须将它们添加到 pom.xml 中,以便每个开发人员始终能够进行构建。
底线是:如果您可以构建具有完全空的存储库的项目,那么您的
pom.xml
就可以了。Apparently your Hibernate dependency is missing
<version>
tag:Note that you don't have to specify version of dependencies previously declared in
<dependencyManagement>
.Old answer:
Every build script (not only with Maven) should be reproducible and independent from environment. Standard pom.xml (called super pom), which every
pom.xml
inherits from, already defines main Maven central repository:You don't have to define this repository, and you don't have to define any others if all your dependencies are there. On the other hand if you are using some external repositories, you must add them to
pom.xml
, so that every developer is always able to build.The bottom line is: if you can build the project having a completely empty repository, your
pom.xml
is fine.不建议在 POM 文件中定义存储库,因为这会导致很多问题(Maven 将在这些存储库中搜索任何工件,甚至是 Central 中可用的工件,可移植性差,...)
最佳方法:设置存储库管理器(Artifactory、Nexus)并编辑 settings.xml 文件以使用存储库管理器作为镜像。
第二种最佳方法:在 settings.xml 文件中定义所需的存储库,而不是在 pom.xml 文件中。
poms 中的存储库是一个坏主意。
It's not advisable to define repositories in POM files as that causes a lot of issues (Maven will search those repositories for ANY artifact even the ones available at Central, poor portability, ...)
Best approach: Setup a repository manager (Artifactory, Nexus) and edit your settings.xml file to use the repo manager as a mirror.
Second best approach: Define the required repositories in your settings.xml file, not in your pom.xml files.
Repositories in poms is a bad idea.