在 maven 工程中引用到了一個 jar 包 commons-io-2.4.jar,因爲被引用的 jar 包依賴 hibernate-jpa-2.0-api ,而 hibernate-jpa-2.0-api 存在 bug ,會報出java
Error: java.lang.NoSuchMethodError:javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
或api
java.lang.NoSuchMethodError:javax.persistence.Table.indexes()[Ljavax/persistence/Index;
等相似的錯誤。因爲主工程一樣存在對 hibernate-jpa-2.0-api 的依賴,先將主工程的 pom.xml 修改,在 MyEclipse 中的 MavenDependencies 中發現仍然存在 hibernate-jpa-2.0-api-1.0.1.Final.jar 的引用,顯而易見,這個存在 bug 的 hibernate-jpa 版本是由 commons-io-2.4.jar 依賴引入的,爲排除該依賴,在主工程的 pom.xml 文件中對依賴作以下修改:
maven
修改前:ide
<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency>
修改後:spa
<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> <!-- 添加排除tag --> <exclusions> <exclusion> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> </exclusion> <!-- 和<dependency>tag相同,能夠添加多個<exclusion>排除多個依賴 --> </exclusions> </dependency>
如今在 MyEclipse 中的 Maven Dependencies 中發現已經沒有了對 hibernate-jpa-2.0-api.jar 的引用。hibernate
補充:xml
如何發現 commons-io-2.4.jar 依賴 hibernate-jpa-2.0-api.jar ,經過 MyEclipse 中 pom.xml 文件下的 Dependency Graph 視圖,以下圖所示:blog
經過 Dependency Graph 能夠看出具體 jar 包依賴哪些其餘 jar 包。ip
完。ci