2012-12-04 34 views
12

我正在使用Maven 3,我试图在webapp文件夹下添加META-INF文件夹。所以,我想做到以下几点:Maven WebApp META-INF context.xml

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 /资源我添加了一个META-INF \ context.xml的。当WAR文件使用mvn包打包时,结构如下所示:

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 \主\资源移除META-INF文件夹,并直接把它下的webapp \ META-INF。 context.xml显示,但是当部署到Tomcat中时,我定义的上下文根不起作用。

+0

不确定这是否可行,但您可以尝试将'META-INF'文件夹移动到'resources/META-INF'。 – frececroka

+0

所以你最初的问题已经消失了? –

+0

不,问题依然存在。 – user1646481

回答

22

将您的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> 

网络资源的标签是什么是重要的? 希望这有助于

+0

这适用,但是在Tomcat中,当我加载Web应用程序时,上下文根不起作用。 – user1646481

+0

此链接可能会帮助你,http://stackoverflow.com/questions/2593472/define-servlet-context-in-war-file – dinukadev

1

使用标签来代替。以上答案使用src/main/resources中的所有内容复制到Web应用程序的根目录,这可能不是您想要执行的操作,也不是您想要遵循的示例。