Java 使用context.xml配置WebApp以使用Tomcat

Java 使用context.xml配置WebApp以使用Tomcat,java,tomcat,maven,web-applications,Java,Tomcat,Maven,Web Applications,我正在使用Maven 3构建我的项目。我有一个web应用程序,我想定义自定义根。根据Tomcat 6文档,它说: 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 [we

我正在使用Maven 3构建我的项目。我有一个web应用程序,我想定义自定义根。根据Tomcat 6文档,它说:

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. 
我想使用我定义的自定义根。这是如何实现的,因为当我定义custom context.xml文件时,在Tomcat中看不到路径。根据上面提到的,如果没有为上下文提供上下文描述符,Tomcat将使用默认值配置上下文。我已经在Context.xml中定义了我的上下文描述符,如下所示:

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

当我将deploy.war部署到Tomcat中时,我无法访问/data1不工作。然而,/数据起作用。部署war文件时,它具有位于context.xml的META-INF

我的POM文件:

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

4.0.0
com.data

查看pom,war文件的名称应为“webchannel”


您不必添加context.xml。只需让url由war文件名和您在project中创建的任何映射确定。

刚刚编辑。应该是数据战。我不希望名称由war文件名决定。我想使用我定义的上下文根。这怎么可能呢?为什么不把战争改名呢?有实际原因吗?这是正常的,所以违背它是相当奇怪的。有几个原因。我正在为我的公司做一个项目。需求是使用我们定义的上下文根,而不是像Maven这样的任何其他构建。要求已经改变。所以我将重命名war文件。