美文网首页
maven 自动部署tomcat-方案1

maven 自动部署tomcat-方案1

作者: heichong | 来源:发表于2017-01-16 15:12 被阅读66次

    自动部署方案1:通过tomcat提供的war包管理页面上传war包。具体请看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>
        <parent>
            <groupId>com.ctitc</groupId>
            <artifactId>deep</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
        <groupId>com.ctitc</groupId>
        <artifactId>deep-api</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
        <name>deep-api Maven Webapp</name>
        <url>http://maven.apache.org</url>
        <dependencies>
    
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <scope>test</scope>
            </dependency>
            <!-- apache common -->
            <dependency>
                <groupId>commons-net</groupId>
                <artifactId>commons-net</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
            </dependency>
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
            </dependency>
            <dependency>
                <groupId>commons-beanutils</groupId>
                <artifactId>commons-beanutils</artifactId>
            </dependency>
            <dependency>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
            </dependency>
    
            <!-- 日志 -->
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
            </dependency>
            <!-- spring核心包 -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context-support</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </dependency>
            <!-- 切面 -->
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjrt</artifactId>
            </dependency>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
            </dependency>
    
            <!-- springfox swagger2 -->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <scope>provided</scope>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>javax.servlet.jsp-api</artifactId>
                <scope>provided</scope>
            </dependency>
    
        </dependencies>
    
        <profiles>
            <!-- 1.本地开发环境 -->
            <profile>
                <id>dev</id>
                <properties>
                    <is_product>0</is_product>
                </properties>
                <!-- 默认激活 -->
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <build>
                    <!-- war包名称 -->
                    <finalName>${project.artifactId}-${project.version}</finalName>
                    <plugins>
                        <!-- 打包策略 -->
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-war-plugin</artifactId>
                            <configuration>
                                <warName>${project.artifactId}-dev</warName>
                                <archive>
                                    <addMavenDescriptor>false</addMavenDescriptor>
                                </archive>
                                <webResources>
                                    <resource>
                                        <!-- 指定路径 -->
                                        <directory>src/main/resources/env-dev</directory>
                                        <!-- directory内的资源会被copy到此路径下 -->
                                        <targetPath>WEB-INF/classes</targetPath>
                                        <filtering>true</filtering>
                                    </resource>
                                </webResources>
                            </configuration>
                        </plugin>
                        <!-- tomcat插件 -->
                        <plugin>
                            <groupId>org.apache.tomcat.maven</groupId>
                            <artifactId>tomcat7-maven-plugin</artifactId>
                            <version>2.2</version>
                            <configuration>
                                <port>8080</port>
                                <path>/deep-api</path>
                                <uriEncoding>UTF-8</uriEncoding>
                                <server>tomcat7</server>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
            <!-- 2.测试环境 -->
            <profile>
                <id>test</id>
                <properties>
                    <is_product>0</is_product>
                </properties>
                <build>
                    <!-- war包名称 -->
                    <finalName>${project.artifactId}-${project.version}</finalName>
                    <plugins>
                        <!-- 打包策略 -->
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-war-plugin</artifactId>
                            <configuration>
                                <archive>
                                    <addMavenDescriptor>false</addMavenDescriptor>
                                </archive>
                                <webResources>
                                    <resource>
                                        <!-- 指定路径 -->
                                        <directory>src/main/resources/env-test</directory>
                                        <!-- directory内的资源会被copy到此路径下 -->
                                        <targetPath>WEB-INF/classes</targetPath>
                                        <filtering>true</filtering>
                                    </resource>
                                </webResources>
                            </configuration>
                        </plugin>
                        <!-- tomcat插件 -->
                        <plugin>
                            <groupId>org.apache.tomcat.maven</groupId>
                            <artifactId>tomcat7-maven-plugin</artifactId>
                            <version>2.2</version>
                            <configuration>
                                <!-- 配置项目自动发布服务器 -->
                                <url>http://192.168.3.22:8080/manager/text</url>
                                <path>/${project.artifactId}</path>
                                <update>true</update>
                                <!-- <warFile>target/${profiles.activation}.war</warFile> -->
                                <!-- maven setting.xml中配置的用户名密码,也可以直接在此处配置用户名密码 -->
                                <server>test-tomcat</server>
                                <!-- <username>admin</username> <password>12345</password> -->
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
            <profile>
                <!-- 生产环境 -->
                <id>product</id>
                <properties>
                    <package.env>product</package.env>
                </properties>
            </profile>
        </profiles>
    
        <build>
            <!-- 定义项目的资源信息 -->
            <resources>
                <resource>
                    <!-- 设置主资源目录,此目录下的文件都会被作为资源文件加入到class下 -->
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                    <!-- 打包的资源,路径以directory作为当前位置 -->
                    <includes>
                        <include>**/*.properties</include>
                        <include>**/*.xml</include>
                    </includes>
                    <!-- 不打包的资源,路径以directory作为当前位置 -->
                    <excludes>
                        <exclude>env-dev/**</exclude>
                        <exclude>env-product/**</exclude>
                        <exclude>env-test/**</exclude>
                    </excludes>
                </resource>
            </resources>
    
            <plugins>
                <!-- jdk版本 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
    
            </plugins>
    
        </build>
    </project>
    
    

    相关文章

      网友评论

          本文标题:maven 自动部署tomcat-方案1

          本文链接:https://www.haomeiwen.com/subject/odkpbttx.html