Vjeetje
Vjeetje

Reputation: 5384

let tomcat deploy automaticly with a context

I have a project named 'projectx'. My goal is to execute mvn clean install and let Tomcat use the /target folder to autodeploy the webapp.

I added projectx.xml with the following contents to /tomcat/conf/Catalina/localhost/

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="C:\Users\Username\workspace\projectx-webapp\target" path="/projectx-webapp"/>

I can see in the server log the file projectx.xml is processed succesfully. The webapp is deployed successfully. The site url is localhost:8080/projectx-webapp/ .However when I go to the url, the webapp is not found.

When I deploy the war file manually in tomcat\webapps, the webapp works fine when I go to the specified url. Did I missconfigure something in projectx.xml?

my web.xml:

<web-app id="projectx-webapp" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

 <display-name>Project Web Application</display-name>

 <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
 </servlet>

 <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
 </servlet-mapping>

</web-app>

my pom.xml:

<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>projectx</groupId>
    <artifactId>projectx-webapp</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>projectx-webapp Maven Webapp</name>
    <properties>
        <!-- Generic properties -->
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Spring -->
        <spring.version>4.2.4.RELEASE</spring.version>
    </properties>
    <dependencies>
       <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Below declared dependencies are included for the servers who may complain about servlet/jstl missing dependency -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>projectx-webapp</finalName>
    </build>
</project>

Upvotes: 0

Views: 89

Answers (1)

Andrea Catania
Andrea Catania

Reputation: 1383

As we have verified in the chat, your application are working well the problem is that the context used by the app was /projectx instead of /projectx-webapp that you expected.

This happened because for specify the deployment directory you has created the file apache-tomcat-8.0.30\conf\Catalina\localhost\projectx.xml when you has changed this to apache-tomcat-8.0.30\conf\Catalina\localhost\projectx-webapp.xml the app was deployed with the context you expected /projectx-webapp

Upvotes: 1

Related Questions