Maven 默认 arhcetype:jersey-qucikstart-webapp 无法 运行 webapp - [致命错误]:3:6:

Maven default arhcetype: jersey-qucikstart-webapp unable to run webapp - [Fatal Error] :3:6:

我已经创建了原型 Maven 项目:jersey-quickstart-webapp。我已经添加了我之前准备的项目文件,我不得不在 pom.xml 文件中添加以下内容 <dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <type>jar</type>
    </dependency>

现在完整的文件如下所示:

 <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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.glassfish.jersey.archetypes</groupId>
<artifactId>ParkingSystem</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ParkingSystem</name>

<build>
    <finalName>ParkingSystem</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>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
     <type>jar</type>
    </dependency>
    <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>
    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-binding</artifactId>
    </dependency>
</dependencies>
<properties>
    <jersey.version>2.27</jersey.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

我知道错误的意思是根元素不止一个。然而,这是原型的默认文件,并且有 <project> </project> 作为根元素,或者我可能不明白什么?其他所有元素都在 <project> 元素内。我所做的唯一更改是我在 <dependencies> 标记中从顶部开始添加了 javax-servlet 依赖项。我检查了 xmlns,其中 none 是自动关闭的。我在 <properties> 标签中找到了标签 <project.build.sourceEncoding,但我不认为它对根 <project> </project> 元素有影响,无论如何它默认在那里。显然,我遗漏了一些东西,我真的很想了解。

这是我收到的唯一错误消息:
[致命错误]:3:6: 文档中跟在根元素之后的标记必须格式正确。
没有更多信息。

在您的 context.xml 文件中:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ParkingSystem"/>
    <Resource name="sql2226123"
       auth="Container" type="javax.sql.DataSource"
       maxActive="20" maxIdle="5" maxWait="10000"
       username="sqldb" password="xyz123"
       driverClassName="com.mysql.jdbc.Driver"
       url="jdbc:mysql://sql2.freemysqlhosting.net:3306/sql2226123"/>
</Context>

第二行 <Context path="/ParkingSystem"/> 已关闭 Context,因此此文件格式错误。删除最后 / 这一行将解决问题。正确的文件应该是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ParkingSystem">
    <Resource name="sql2226123"
       auth="Container" type="javax.sql.DataSource"
       maxActive="20" maxIdle="5" maxWait="10000"
       username="sqldb" password="xyz123"
       driverClassName="com.mysql.jdbc.Driver"
       url="jdbc:mysql://sql2.freemysqlhosting.net:3306/sql2226123"/>
</Context>