0

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.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Luke_Nuke
  • 461
  • 2
  • 6
  • 23
  • Please post the error messages. – John Aug 25 '18 at 12:46
  • I've updated a question, however, the only error message I got is the one in question title :( – Luke_Nuke Aug 25 '18 at 12:53
  • I mean, sounds like either the element is malformed, or something right after. Maybe we can't see it here. You could post the raw content to something like pastebin. But I'd check for some formatting problems, do you maybe have an editor with XML syntax highlighting? – Benjamin Maurer Aug 25 '18 at 12:55
  • Here it is I put it into pastebin - as XML: https://pastebin.com/sDJTsM3B – Luke_Nuke Aug 25 '18 at 13:02
  • A full message will provide more information about *When* and *Which step* printed out this "Fatal Error". – John Aug 25 '18 at 13:05
  • This pom.xml `validate` fine in my Idea with maven 3. – John Aug 25 '18 at 13:11
  • Here is full output when I'm running project maybe there is any clue? https://pastebin.com/9Pm52cmb – Luke_Nuke Aug 25 '18 at 13:15
  • Yes. The error is raised during `Deploying on Apache Tomcat or TomEE`, so it quite possible not a pom.xml problem, but some xml file in your war. You may try deploying the `ParkingSystem.war` directly to tomcat. Tomcat should give more detailed error message. – John Aug 25 '18 at 14:30
  • Here is my web.xml file: https://pastebin.com/gurLfuGa and context.xml (I've changed sqlDB credentials) https://pastebin.com/kMtrJhm0 also in C://pathToNetbeansProject/MyProject there is following nb-configuration.xml: https://pastebin.com/SE5bFtxj I don't think there is any more xml. However when my project was a web-app, not maven project it worked fine. – Luke_Nuke Aug 25 '18 at 14:40

1 Answers1

1

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>
John
  • 1,654
  • 1
  • 14
  • 21
  • Thank you! Thank you so much :D Ill remember now to check all other XML files in a situation like this! You saved me :) – Luke_Nuke Aug 25 '18 at 18:31