0

我正在使用 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. 

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

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

当我将 deploy.war 部署到 Tomcat 时,我无法访问 /data1 不起作用。但是, /data 有效。部署 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>

我查看了以下网站,但似乎没有帮助:

在 WAR 文件中定义 Servlet 上下文

4

1 回答 1

0

查看你的 pom,war 文件的名称应该是“webchannel”。

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

于 2012-12-04T14:15:04.473 回答