2010-07-17 62 views

回答

1

粘貼這些依賴關係到pom.xml<depdendencies>後應該工作:

<!-- MySQL database driver --> 
<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>5.1.9</version> 
</dependency> 

<!-- Hibernate framework --> 
<dependency> 
    <groupId>hibernate</groupId> 
    <artifactId>hibernate3</artifactId> 
    <version>3.2.3.GA</version> 
</dependency> 


<!-- Hibernate library dependecy start --> 
<dependency> 
    <groupId>dom4j</groupId> 
    <artifactId>dom4j</artifactId> 
    <version>1.6.1</version> 
</dependency> 

<dependency> 
    <groupId>commons-logging</groupId> 
    <artifactId>commons-logging</artifactId> 
    <version>1.1.1</version> 
</dependency> 

<dependency> 
    <groupId>commons-collections</groupId> 
    <artifactId>commons-collections</artifactId> 
    <version>3.2.1</version> 
</dependency> 

<dependency> 
    <groupId>cglib</groupId> 
    <artifactId>cglib</artifactId> 
    <version>2.2</version> 
</dependency> 

<dependency> 
    <groupId>javax.transaction</groupId> 
    <artifactId>jta</artifactId> 
    <version>1.1</version> 
</dependency> 
<!-- Hibernate library dependecy end --> 

http://www.mkyong.com/hibernate/quick-start-maven-hibernate-mysql-example/無恥克隆(加JTA的建議由評論員)

您可能要在調整的版本號依賴關係。

IntelliJ IDEA 9可以根據類名查找Maven依賴關係。如果你開始使用一個當前依賴關係中沒有的類,你可以通過使用Alt-Enter來讓IntelliJ找到它。

我在工作時使用了這個基於Java的Subversion掛鉤實現,效果很好。我可以很容易地將SVNKit和Google Guice依賴項以這種方式很容易地加入到我的項目中。

MySQL在你的情況下可能會更棘手,因爲它在使用Hibernate時更多的是運行時依賴。

+0

春天的依賴性不存在總是擡頭當前版本 - http://blog.springsource.com/2009/12/02/獲得彈簧3人工製品與maven/ – Redlab 2010-07-17 04:05:36

+0

正確的你。我讀了你的問題,但不是題目。 Spring需要什麼特性? Spring中有很多組件,你可能並不需要它們。 – 2010-07-17 11:18:44

+1

這些依賴關係確實是過時的,我不推薦使用它們(Hibernate現在正在使用SLF4J)。 – 2010-07-17 12:48:27

2

首先,我從文物中分離版本:

<properties> 
    <spring.version>3.0.3.RELEASE</spring.version> 
    <hibernate.version>3.5.3-Final</hibernate.version> 
    <mysql.version>5.1.13</mysql.version> 
    <junit.version>4.7</junit.version> 
</properties> 

然後我這樣引用它們:

<dependencies> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>${mysql.version}</version> 
     <!-- perhaps using scope = provided, as this will often 
     be present on the app server --> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <!-- or hibernate-entitymanager if you use jpa --> 
     <version>${hibernate.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>${junit.version}</version> 
     <scope>test</scope> 
    </dependency> 

</dependencies> 

這樣,你保持版本都在一個地方,可以很容易地更新它們,特別是如果你參考例如多個春天文物。

BTW:這應該是當前的版本,但可以使用MvnRepository.com