gpt4 book ai didi

java - 使用 context.xml 配置 WebApp 以使用 Tomcat

转载 作者:行者123 更新时间:2023-11-28 23:46:26 27 4
gpt4 key购买 nike

我正在使用 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 中看不到该路径。根据上面提到的,如果没有为上下文提供上下文描述符,则Tomcat使用默认值配置上下文。我已经在 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>

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

Define Servlet Context in WAR-File

最佳答案

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

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

关于java - 使用 context.xml 配置 WebApp 以使用 Tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13704634/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com