Maven WebApp META-INF context.xml [英] Maven WebApp META-INF context.xml

查看:97
本文介绍了Maven WebApp META-INF context.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Maven 3,我正在尝试在webapp文件夹下添加META-INF文件夹。所以我想尝试以下操作:

I am using Maven 3 and I am trying to add META-INF folder under webapp folder. So I am trying to do the following:

src
 main
  webapp
   META-INF
    context.xml
   WEB-INF

以下是我的POM文件:

Below is my POM file:

<?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包打包WAR文件时,结构如下所示:

Under src/main/resources I have added a META-INF\context.xml. When the WAR file is packaged using mvn package the structure looks like this:

data
 webapp
  META-INF
  WEB-INF
  index.jsp

WEB下的相关文件-INF可见一斑。但是,META-INF文件夹是空白的。我的默认Maven将在WEB-INF / classes下添加资源。

The relevant files under WEB-INF can be seen. However, the META-INF folder is blank. My default Maven will add resources under the WEB-INF/classes.

我想要特别想拥有:

data
 webapp
  META-INF
   context.xml
  WEB-INF

这怎么可能?我尝试了其他的东西,但它仍然没有用。 context.xml包含以下内容:

How is this possible? I have tried other things, but still it does not work. The context.xml contains the following:

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

我试过从src \\\\\\\\\\\\\\\\\\\\\\\\\\\\\在webapp\META-INF下。 context.xml显示但是当部署到Tomcat时,我定义的上下文根不起作用。

I have tried removing the META-INF folder from src\main\resources and directly put it under webapp\META-INF. The context.xml displays but when deployed into Tomcat, the context root that I have defined does not work.

推荐答案

放入你的META src / main / resources中的-INF文件夹。

Put your META-INF folder within src/main/resources.

把它放在你的pom.xml上...抱歉我以前错过了它;

Put this on your pom.xml... sorry i missed it before;

<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>

网络资源标签是重要的...
希望这有帮助

the web resources tag is what is important... Hope this helps

这篇关于Maven WebApp META-INF context.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆