eclipse 使用 Maven pom.xml 将战争文件部署到 Tomcat 根目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10449354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deploying a War File to Tomcat Root With Maven pom.xml
提问by Dominik
Assuming the following pom.xml
maven would build a client.war
file which when deployed to Tomcat will have the URL www.server.com:8080/client/
假设以下pom.xml
maven 将构建一个client.war
文件,该文件在部署到 Tomcat 时将具有 URLwww.server.com:8080/client/
What would one have to change so the application can be reached at the server root www.server.com:8080/
?
必须更改什么才能在服务器根目录下访问应用程序www.server.com:8080/
?
<project> <modelVersion>4.0.0</modelVersion> <groupId>...</groupId> <artifactId>client</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>...</name> <url>http://maven.apache.org</url> <build> <resources> <resource> <directory>target/generated-resources</directory> </resource> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <plugins> ... </plugins> <finalName>client</finalName> </build> ... </project>
<project> <modelVersion>4.0.0</modelVersion> <groupId>...</groupId> <artifactId>client</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>...</name> <url>http://maven.apache.org</url> <build> <resources> <resource> <directory>target/generated-resources</directory> </resource> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <plugins> ... </plugins> <finalName>client</finalName> </build> ... </project>
回答by user944849
I believe you can leave the war named client.war if you'd like. Then configure the tomcat6 plugin, setting the path like this:
如果您愿意,我相信您可以离开名为 client.war 的War。然后配置tomcat6插件,设置路径如下:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<!-- put the configuration in an execution if you want to... -->
<configuration>
<path>/</path>
<warFile>${project.build.directory}/client.war</warFile>
<!-- other config options here -->
</configuration>
</plugin>
I haven't used tomcat7 version of the plugin, but I'm guessing it's similar.
我没有用过tomcat7版本的插件,但我猜它是相似的。
回答by Noremac
Since you're using the combination of eclipse, tomcat, and maven, I'm going to make the guess that the m2e-wtp plugin is in use here. There's a FAQ that addresses this. This also shows though how to change your context root in a maven specific way (using the war plugin for specifying a finalName for the war) which results in a correctly named war file (such as ROOT.war as mentioned in other answers.
由于您使用的是 eclipse、tomcat 和 maven 的组合,因此我将猜测这里使用的是 m2e-wtp 插件。有一个常见问题解答解决了这个问题。这也显示了如何以 maven 特定方式更改上下文根(使用 war 插件为 war 指定 finalName),这会导致正确命名的 war 文件(例如其他答案中提到的 ROOT.war 。
回答by vitorrrr
Maven war plugin (which is defined on super-pom by default) will only generate a war file. It's up to you to set up your app on Tomcat. If you want to add the "deploy to a container" to your maven build, go with Tomcat Maven Pluginor Cargo Maven Plugin.
Maven war插件(默认定义在super-pom上)只会生成一个war文件。在 Tomcat 上设置应用程序取决于您。如果您想将“部署到容器”添加到您的 Maven 构建中,请使用Tomcat Maven Plugin或Cargo Maven Plugin。
What you want has nothing to do with Maven, actually. Setting your war name to ROOT.war should do it (<finalName>ROOT</finalName>
on your build section), but if you want to add your context.xml
to the war file, you could do something like (assuming src/main/webapp
is your webapp folder defined by maven):
实际上,您想要的与 Maven 无关。将您的War名称设置为 ROOT.war 应该这样做(<finalName>ROOT</finalName>
在您的构建部分),但是如果您想将您context.xml
的添加到War文件,您可以执行以下操作(假设src/main/webapp
您的 webapp 文件夹是由 maven 定义的):
`<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<webResource>
<directory>${basedir}/src/main/webapp/META-INF</directory>
<includes>
<include>context.xml</include>
</includes>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
</webResource>
</webResources>
</configuration>
</plugin>
`
`