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

62 views Asked by At

I've created the archetype maven project: jersey-quickstart-webapp. I've added the project files I've prepared before and I had to add the following <dependency> in the pom.xml file:

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

and now full file looks like this:

 <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>

I know that error means that there is more than one root element. However this is the default file from the archetype and there is <project> </project> as the root element, or maybe I don't understand something? Every other elements are within <project> element. The only change I made is that I added javax-servlet dependency as first from the top in the <dependencies> tag. I've checked xmlns and none of those is self-closing. I found tag <project.build.sourceEncoding in the <properties> tag but I don't think it has an effect on the root <project> </project> element anyway it was by default there. Clearly, I'm missing something and I really want to understand.

This is the only error message I got:
[Fatal Error] :3:6: The markup in the document following the root element must be well-formed.
No more info.

1

There are 1 answers

1
John On BEST ANSWER

In your context.xml file:

<?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>

The second line <Context path="/ParkingSystem"/> has closed Context, so this file is malformed. Delete the last / this line will fix the problem. The correct file should be like:

<?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>