POM 依赖项不起作用(Eclipse、Maven、POM)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6088256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
POM dependencies not working (Eclipse, Maven, POM)
提问by Jasper
I have a project in Eclipse (Helios), with Maven pom.xml. My project is a web app that will use Hibernate, MySQL.
我在 Eclipse (Helios) 中有一个项目,使用 Maven pom.xml。我的项目是一个将使用 Hibernate、MySQL 的 Web 应用程序。
But i have endless woes in getting pom.xml right. I am new to maven, and can't believe setting up dependencies is so tough(do others have similar expierience / or am i dumb).
但是我在正确获取 pom.xml 方面遇到了无尽的麻烦。我是 maven 的新手,无法相信设置依赖项是如此困难(其他人是否有类似的经验/或者我是愚蠢的)。
My pom.xml is here:
我的 pom.xml 在这里:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyProj1</groupId>
<artifactId>MyProj1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
<repository>
<id>Scala Tools</id>
<name>Scala Tools</name>
<url>http://scala-tools.org/repo-releases/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.4.Final</version>
</dependency>
<!--
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.6.4.Final</version>
</dependency>
-->
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.6-brew</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1-jboss</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.16</version>
</dependency>
</dependencies>
</project>
The error i get is:
我得到的错误是:
Missing artifact commons-logging:commons-logging:jar:1.1.1:compile
Missing artifact org.hibernate:hibernate-entitymanager:jar:3.6.4.Final:compile
Missing artifact javassist:javassist:jar:3.12.0.GA:compile
Missing artifact org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
Missing artifact org.slf4j:slf4j-api:jar:1.6.1:compile
Missing artifact org.hibernate:hibernate-core:jar:3.6.4.Final:compile
Missing artifact commons-collections:commons-collections:jar:3.1:compile
Missing artifact org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
Missing artifact javax.transaction:jta:jar:1.1:compile
Missing artifact antlr:antlr:jar:2.7.6-brew:compile
Missing artifact dom4j:dom4j:jar:1.6.1-jboss:compile
Missing artifact xml-apis:xml-apis:jar:1.0.b2:compile
Missing artifact asm:asm:jar:1.4.3:compile
Missing artifact cglib:cglib:jar:2.1.1:compile
---
All the above errors go away, if i remove the mysql dependency from the pom.xml file. I am totally confused why mysql should have dependency on these.
如果我从 pom.xml 文件中删除 mysql 依赖项,上述所有错误都会消失。我完全困惑为什么 mysql 应该依赖这些。
Isn't Maven supposed to resolve these dependencies automatically? Afterall isn't that the whole idea of using Maven.
Maven 不是应该自动解决这些依赖关系吗?毕竟这不是使用 Maven 的全部想法。
Experts please guide me in the right direction.
请专家指导我正确的方向。
回答by Wouter Lievens
You can search for dependencies here:
您可以在此处搜索依赖项:
For Maven2 it is:
对于 Maven2,它是:
http://repo1.maven.org/maven2/
http://repo1.maven.org/maven2/
Hibernate in particular is notoriously difficult for setting up the right dependencies.
众所周知,Hibernate 很难设置正确的依赖项。
See: How can I use Maven to get the latest Hibernate release?