gpt4 book ai didi

java - 没有WEB-INF如何给tomcat部署静态资源?

转载 作者:行者123 更新时间:2023-11-28 22:40:02 26 4
gpt4 key购买 nike

我想创建一个只包含静态资源的war 包。例如:

/src/main/resources/files/example.xml

因此,我创建了以下 maven 配置:

<?xml version="1.0" encoding="UTF-8"?>
<project>
<groupId>my.domain</groupId>
<artifactId>testpackage</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>

tomcat8 上部署时,我得到以下结构:

localhost:8080/testpackage/WEB-INF/classes/files/example.xml

我想要的是能够直接使用访问静态文件:

localhost:8080/testpackage/files/example.xml

问题:我如何创建一个可部署的 war ,在没有 /WEB-INF/classes 的路径中爆炸?

(我知道我可以手动将文件复制到 /webapps 文件夹中。但其他人应该能够通过 tomcat 管理器 Web 界面部署静态内容,因此需要一场适当的 war ) .

最佳答案

Web 资源位于 src/main/webapp 下。

src/main/resources 用于类路径资源。

参见 project layout documentation .

关于java - 没有WEB-INF如何给tomcat部署静态资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44800811/

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