我正在尝试用maven构建我的java hibernate项目。 但是当我尝试这样做时,看起来似乎没有可用的依赖项?
我现在在我的项目中有这个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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.viralpatel.hibernate</groupId>
<artifactId>HibernateHelloWorldXML</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>HibernateHelloWorldXML</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>1.0.1.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.10</version>
</dependency>
</dependencies>
</project>
当我尝试使用mvn构建时,我收到此错误:
[WARNING] An error occurred during dependency resolution.
Failed to retrieve javax.transaction:jta-1.0.1B
Caused by: Failure to find javax.transaction:jta:jar:1.0.1B in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will
not be reattempted until the update interval of central has elapsed or updates are forced
Try downloading the file manually from:
http://java.sun.com/products/jta
Then, install it using the command:
mvn install:install-file -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -Drepository
Id=[id]
Path to dependency:
1) net.viralpatel.hibernate:HibernateHelloWorldXML:jar:1.0-SNAPSHOT
2) org.hibernate:hibernate-annotations:jar:3.3.1.GA
3) org.hibernate:hibernate:jar:3.2.6.ga
4) javax.transaction:jta:jar:1.0.1B
javax.transaction:jta:jar:1.0.1B
from the specified remote repositories:
central (http://repo.maven.apache.org/maven2, releases=true, snapshots=false)
我搜索了这个错误并发现很多人不得不在他们的pom.xml文件中更改他们的hibernate-core依赖版本但是好像我没有hibernate-core,所以我怎么能解决这个问题?
答案 0 :(得分:10)
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.3.2.ga</version>
</dependency>
它有一个推荐的JTA 1.1依赖。
或强>
您可以添加&#34; http://download.java.net/maven/2&#34;作为pom.xml或settings.xml中的新存储库
<repository>
<id>java.net.m2repo</id>
<name>java.net Maven 2 Repository</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
对于Sun或oracle提供的任何JEE库。添加以下存储库
<repositories>
<repository>
<id>GlassFish</id>
<name>GlassFish Maven Repository</name>
<url>http://download.java.net/maven/glassfish/</url>
</repository>
<repository>
<id>java.net.m1repo</id>
<name>java.net Maven 1 Repository</name>
<url>http://download.java.net/maven/1/</url>
<layout>legacy</layout>
</repository>
<repository>
<id>java.net.m2repo</id>
<name>java.net Maven 2 Repository</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
</repositories>
答案 1 :(得分:8)
我遇到同样的问题,我从http://www.java2s.com/Code/Jar/j/Downloadjta101Bjar.htm手动下载了jta-1.0.1B.jar文件
我正在使用Netbeans7.3。我在项目中扩展了dependencies文件夹,发现jta-1.0.1B.jar带有小黄色图标(用于出错)。然后我右键单击并使用选项&#34;手动安装工件&#34;并指向文件jta-1.0.1B.jar的位置。解决了。
答案 2 :(得分:2)
步骤:1我遇到同样的问题,我从http://www.java2s.com/Code/Jar/j/Downloadjta101Bjar.htm手动下载了jta-1.0.1B.jar文件,并将其保存在F盘中。
步骤:2执行以下命令 mvn install:install-file -Dfile = F:\ jta-1.0.1B.jar -DgroupId = javax.transaction -DartifactId = jta -Dversion = 1.0.1B -Dpackaging = jar
答案 3 :(得分:0)
您可以从 http://www.java2s.com/Code/Jar/j/Downloadjta101bjar.htm 下载此jar,并使用以下命令将其安装在本地Maven中:
mvn install:install-file -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar -Dfile=jta-1.0.1b.jar
答案 4 :(得分:-1)
请在pom.xml中添加以下repo -
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/
</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>