项目构建错误:不可解析的 POM:重复标记:“依赖项”(位置:已看到 START_TAG ...</属性>\r\n\r\n\t<依赖项>... @55:16)

San*_*tha 0 maven

我只是 java Rest api Web 服务的初学者。我想在我的项目中添加 GSON。所以我只是使用 java 构建路径中的 add external jar 选项添加了 gson jar 并在 pom.xml 文件中添加了依赖项,但它显示了以下错误,

项目构建错误:不可解析的 POM:重复的标签:“依赖项”(位置:看到 START_TAG ...\r\n\r\n\t...@55:16)

您能给我一个解决这个问题的想法吗?

这是 pom.xml 文件,

http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.example.feeds</groupId>
<artifactId>RESTfullProject</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>RESTfullProject</name>

<build>
    <finalName>RESTfullProject</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>${jersey.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
        <!-- artifactId>jersey-container-servlet</artifactId -->
    </dependency>
    <!-- uncomment this to get JSON support <dependency> <groupId>org.glassfish.jersey.media</groupId> 
        <artifactId>jersey-media-moxy</artifactId> </dependency> -->
</dependencies>
<properties>
    <jersey.version>2.16</jersey.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.1</version>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

Sau*_*pal 6

您应该将所有<dependency>标签添加到一个<dependencies>标签中。您不需要将每个依赖项包含在单独的依赖项标记下。

正确的方式:

    <dependencies>
       <dependency1>
       </dependency1>

       <dependency2>
       </dependency2>
    </dependencies>
Run Code Online (Sandbox Code Playgroud)