java - Maven Eclipse 集成问题

标签 java xml eclipse maven pom.xml

我在 Maven 集成方面遇到问题。我最近下载了 Eclipse Luna(带有 JDK 8 补丁)并在 Ubuntu 操作系统上使用它。

我已经使用简单的 Artifact 创建了一个 Maven 项目,现在当我在 pom.xml 文件中添加写入一些依赖项然后测试它时,Maven 构建成功,但在我的 Java 构建路径中,JRE 系统库 [J2SE -1.5 ] 存在,但尽管在 POM.xml 文件中写入了一些依赖项,但我的 Maven 依赖项不包含任何内容。

这是我的 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>com.test</groupId>
    <artifactId>testproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencyManagement>

        <dependencies>
            <dependency>
                <groupId>org.apache.lucene</groupId>
                <artifactId>lucene-core</artifactId>
                <version>5.0.0</version>
            </dependency>

            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.10-FINAL</version>
            </dependency>

        </dependencies>

    </dependencyManagement>


</project>

由于我的 Maven 依赖项不存在于我的构建路径中,因此我无法使用 Maven 添加的库。

最佳答案

您必须将依赖项放在 <dependencyManagement> 之外

    <dependencies>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>5.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.10-FINAL</version>
        </dependency>

    </dependencies>

参见documentation为了什么<dependencyManagement>应该使用:

The dependency management section is a mechanism for centralizing dependency information. When you have a set of projects that inherits a common parent it's possible to put all information about the dependency in the common POM and have simpler references to the artifacts in the child POMs.

关于java - Maven Eclipse 集成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28825983/

相关文章:

php - 使用 PHP 创建 XML 站点地图

Eclipse 中的 Java 属性 UTF-8 编码

android - googleMap.getMyLocation();无法获取当前位置

java - 如何将类添加到 Eclipse 中 MBean Explorer 的类路径

java - 使用谷歌应用引擎时显示迭代错误

java - 基于值的 XmlUnit 顺序

java - getter 和 setter 方法应该有什么名称

xml - 更改XML属性的值会删除其他属性

java - 在java中解析速度变量

java - 导入android项目的问题