簡體   English   中英

Maven WebApp META-INF context.xml

[英]Maven WebApp META-INF context.xml

我正在使用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包打包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>

網絡資源標簽是重要的......希望這會有所幫助

請改用標簽。 上面的答案使用將src / main / resources中的所有內容復制到Web應用程序的根目錄,這可能不是您想要做的,也不是您想要遵循的示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM