Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven WebApp META-INF context.xml

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

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>

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

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.

I want specifically would like to have:

data
 webapp
  META-INF
   context.xml
  WEB-INF

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

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.

like image 697
user1646481 Avatar asked Dec 04 '12 10:12

user1646481


People also ask

What is context xml in Meta-INF?

context. xml file is the application deployment descriptor for the Apache Tomcat server. In a deployed application, this file is located in the META-INF folder of the web application directory or the WAR file, for example, tomcat/webapps/app-core/META-INF/context.

Where does web xml go in Maven project?

Store resources under webapp/WEB-INF In particular, note that the web. xml file is stored at ProjectDir/src/main/webapp/WEB-INF/web. xml .

What is meta-inf in Tomcat?

The META-INF folder is the home for the MANIFEST. MF file. This file contains meta data about the contents of the JAR. For example, there is an entry called Main-Class that specifies the name of the Java class with the static main() for executable JAR files.

What is web xml in Maven project?

In Java web applications, web. xml is the standard name of the deployment descriptor. We can create a web application using Maven or a dynamic web project using Eclipse. Eclipse doesn't create the default deployment descriptor web.


1 Answers

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

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

like image 175
dinukadev Avatar answered Sep 19 '22 15:09

dinukadev