0

I am using Maven 3 to build my project. I have a web application that I want to define the custom root. According to the Tomcat 6 Documentation it says:

The locations for Context Descriptors are: 
1.  $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml 
2.  $CATALINA_BASE/webapps/[webappname]/META-INF/context.xml

Files in (1) are named [webappname].xml but files in (2) are named context.xml. 
If a Context Descriptor is not provided for a Context, Tomcat configures the Context using default values. 

I want to use a custom root that I define. How can this be achived because when I define the custom context.xml file, the path is not being seen in Tomcat. According to the above, it mentions if a Context Descriptor is not provided for a Context, Tomcat configures the Context using default values. I have already defined my Context Descriptor as seen below in context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/data1"/>

When I deploy deploy.war, into Tomcat I cannot access /data1 does not work. However, /data works. When the war file is deployed, it has META-INF with the context.xml located.

My POM file:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
 <groupId>com.data</groupId>
 <artifactId>Java-WebApp</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>war</packaging>

<name>Java-Web Application</name>

<!-- Shared version number properties-->
<properties>
<org.springframework.version>3.0.6.RELEASE</org.springframework.version>
</properties>

<dependencies>
   <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
</dependencies>
<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0</version>
        <configuration>
            <webResources>
                <resource>
                    <directory>${project.basedir}/src/main/resources</directory>
                </resource>
            </webResources>
        </configuration>
    </plugin>
</plugins>
<finalName>data</finalName>
</build>

<parent>
<groupId>com.data</groupId>
<artifactId>Java-Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
</project>

I have looked into the following website but don't seem to help:

Define Servlet Context in WAR-File

Community
  • 1
  • 1
user1646481
  • 1,267
  • 6
  • 21
  • 29

1 Answers1

0

Looking at your pom, the name of the war file should be "webchannel".

You don't have to add a context.xml. Just let the url be determined by war file name, and any mappings you have created in project.

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • Just edited. It should be data.war. I don't want the name to be determined by the war file name. I would like to use the context root that I define. How is this possible? – user1646481 Dec 04 '12 at 14:20
  • why not just rename the war - is there an actual reason ? Its the norm so going against it is rather weird. – NimChimpsky Dec 04 '12 at 14:20
  • Several reasons. I am working on a project for my company. The requirement is to use the context root that we define and not by any other build like Maven. – user1646481 Dec 04 '12 at 14:21
  • Don't worry. The requirement has changed. So I will just rename the war file. – user1646481 Dec 04 '12 at 14:28