0

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

    <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>元素内。我所做的唯一更改是我将 javax-servlet 依赖项添加为<dependencies>标记中从顶部开始的第一个。我检查了 xmlns,但没有一个是自动关闭的。我在标签<project.build.sourceEncoding中找到了<properties>标签,但我认为它对根<project> </project>元素没有影响,无论如何它默认存在。显然,我错过了一些东西,我真的很想了解。

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

4

1 回答 1

1

在您的 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>
于 2018-08-25T15:25:34.293 回答