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

标签 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 [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/

相关文章:

使用 docker 的 Spring Boot 无法找到请求目标错误的有效认证路径

java - 使用 Maven 进行 Jenkins Spring Build 失败,但在本地构建时可以工作

java - 在类路径文件中找不到自动测试的问题

java - 在 Activity 更新时更新 tabpager fragment 数据

java - 如何防止artifactId被附加到<SCM>连接URI?

java - 独一无二的元素

file - 在没有数据库的情况下保存与 webapplication 相关的数据

tomcat - 访问 AWS EC2 实例上的 Tomcat 文件夹

http - 开发网络服务器有哪些不同的方法?

java - 不使用 Windows 任务计划程序来计划可执行文件