如何将带有Maven的WAR部署到Tomcat? [英] How to deploy WAR with Maven to Tomcat?

查看:73
本文介绍了如何将带有Maven的WAR部署到Tomcat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Maven与Eclipse结合使用.是否可以构建项目,然后将构建的WAR文件部署到Tomcat服务器?

I use the Maven with Eclipse. Is possible build the project and then deploy built WAR file to Tomcat server?

我使用Windows.我可以构建WAR文件,也可以将其手动部署在服务器上.但是我想在构建操作后自动部署WAR文件,它不起作用.我是Maven的新手.

I use Windows. I can build WAR file, and also deploy it on the server manually. But I want to deploy the WAR file automatically after build action and it doesn't work. I am novice in Maven.

我应该在运行配置中设置一些内容吗?我已将目标设置为install值.

Should I set something in my run configuration? I have set goals to install value.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>HelloWorld</groupId>
<artifactId>HelloWorld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>HelloWorld</name>

<properties>
    <spring.version>3.2.2.RELEASE</spring.version>
</properties>

<dependencies>

    <!-- Java Server Pages Standard Tag Library -->
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>


    <!-- Spring 3 dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
</dependencies>

<build>
    <directory>${project.basedir}/target</directory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>install</id>
                    <phase>install</phase>
                    <goals>
                        <goal>sources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- Maven Tomcat Plugin -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>tomcat-maven-plugin</artifactId>
            <configuration>
                <server>Apache_Tomcat_7_x86</server>
                <warFile>${project.build.directory}/HelloWorld-0.0.1-SNAPSHOT.war</warFile>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
            </configuration>
        </plugin>
    </plugins>
</build>

此外,我在路径~/.m2/settings.xml中更改了settings.xml文件.

Furthermore I changed settings.xml file in path ~/.m2/settings.xml.

settings.xml

  <servers>
      <server>
        <id>Apache_Tomcat_7_x86</id>
        <username>admin</username>
        <password>admin</password>
      </server>
  </servers>

推荐答案

同时我解决了它.有几个问题.

Meanwhile I resolved it. There were a few issues.

首先,我在Eclipse 运行配置中将 Goal 设置为tomcat:deploy.

Firstly I set Goal in the Eclipse run configuration to tomcat:deploy.

然后我更改了pom.xml以下

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>tomcat-maven-plugin</artifactId>
  <configuration>
    <url>http://localhost:8080/manager/text</url>
    <server>Apache_Tomcat_7_x86</server>
    <path>/HelloWorld</path>
  </configuration>
</plugin>

配置中的URL取决于Tomcat版本.对我来说,作品text,对我来说,作品html在URL末尾.当然,必须在tomcat-users.xml中将角色设置为manager-scriptmanager-gui.

URL in configuration depends on Tomcat version. For me works text, for others works html on end of URL. And of course, in tomcat-users.xml must be set role manager-script or manager-gui.

也许对其他人有帮助.

这篇关于如何将带有Maven的WAR部署到Tomcat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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