我正在使用 Maven 3,我正在尝试在 webapp 文件夹下添加 META-INF 文件夹。所以我正在尝试执行以下操作:
src
main
webapp
META-INF
context.xml
WEB-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>
<finalName>data</finalName>
</build>
<parent>
<groupId>com.data</groupId>
<artifactId>Java-Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
</project>
在 src/main/resources 下,我添加了一个 META-INF\context.xml。当使用 mvn package 打包 WAR 文件时,结构如下所示:
data
webapp
META-INF
WEB-INF
index.jsp
可以看到WEB-INF下的相关文件。但是,META-INF 文件夹是空白的。我默认的 Maven 会在 WEB-INF/classes 下添加资源。
我特别想要:
data
webapp
META-INF
context.xml
WEB-INF
这怎么可能?我已经尝试过其他的东西,但仍然没有用。 context.xml 包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/data1"/>
我试过把src\main\resources中的META-INF文件夹去掉,直接放到webapp\META-INF下。 context.xml 显示,但是当部署到 Tomcat 中时,我定义的上下文根不起作用。
最佳答案
将您的 META-INF 文件夹放在 src/main/resources 中。
把它放在你的 pom.xml 上......抱歉我之前错过了;
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>${project.basedir}/src/main/resources
</directory>
</resource>
</webResources>
<warName>mywar</warName>
</configuration>
</plugin>
</plugins>
</build>
网络资源标签很重要... 希望这有帮助
关于java - Maven WebApp META-INF context.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13701300/