使用maven在IntelliJ Idea 12 Ultimate项目中添加新的依赖项

使用maven在IntelliJ Idea 12 Ultimate项目中添加新的依赖项

问题描述:

在尝试使用IntelliJ Idea在hibernate项目中手动添加ehcache依赖项失败后,我决定使用maven并向项目添加了maven框架支持。现在我有一个现有的pom.xml文件,我想添加pom(及其依赖项)来自此位置( http: //repo1.maven.org/maven2/org/hibernate/hibernate-ehcache/4.1.9.Final/ )。
我该怎么做?
我可以在项目中拥有多个pom.xml文件吗?
谢谢。

After I tried unsuccessfully to add ehcache dependencies manually in a hibernate project using IntelliJ Idea , I decided to use maven and I added maven framework support to the project.Now I have an existing pom.xml file and I want to add the pom (with its dependencies) from this location (http://repo1.maven.org/maven2/org/hibernate/hibernate-ehcache/4.1.9.Final/). How do I do that? Can I have more than one pom.xml file in a project? Thank you.

这是我正在使用的当前pom.xml文件:

Here is the current pom.xml file I am using :

<?xml version="1.0" encoding="UTF-8"?>
<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>groupId</groupId>
    <artifactId>HibernateProject1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.9.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>4.1.9.Final</version>
    </dependency>
    </dependencies>


</project>

现在我收到以下错误:

线程main中的异常org.hibernate.HibernateException:找不到/hibernate.cfg.xml

Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found

你可以打开每个IDEA窗口只有一个IDEA项目。但Maven项目可以由多个模块组成,每个模块都有一个拥有自己的 pom.xml 。您还可以在同一个IDEA项目中导入多个Maven项目。

You can open only one IDEA project per IDEA window. But a Maven project can be made of multiple modules, each one having its own pom.xml. You can also import multiple Maven projects in the same IDEA project.

如果您有现有的Maven项目,只需打开根 pom.xml 使用文件>打开,IDEA将询问您是否应作为Maven项目开放(假设您已在IDEA中启用了Maven插件)。当您对 pom.xml 进行更改时,IDEA会建议您重新导入项目,从而添加/删除库以使IDEA项目与Maven项目同步。

If you have an existing Maven project, just open the root pom.xml using File > Open and IDEA will ask you if it should be opened as a Maven project (providing you have enabled the Maven plugin in IDEA). When you make changes to a pom.xml, IDEA will suggest you to reimport the project, thus adding/removing libraries to synchronize the IDEA project with the Maven project.

要向hibernate添加依赖项,请添加以下代码:

To add a dependency to hibernate, add this code:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.1.9.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-ehcache</artifactId>
    <version>4.1.9.Final</version>
</dependency>