Maven--外掛

BtWangZhi發表於2017-10-15

1.1 版本變數設定

    <properties>
        <!--外掛版本變數 start-->
        <tomcat6-maven-plugin.version>2.1</tomcat6-maven-plugin.version>
        <tomcat7-maven-plugin.version>2.2</tomcat7-maven-plugin.version>
        <jetty-plugin.version>8.1.16.v20140903</jetty-plugin.version>

        <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
        <maven-war-plugin.version>2.3</maven-war-plugin.version>
        <maven-resources-plugin.version>2.6</maven-resources-plugin.version>
        <maven-install-plugin.version>2.4</maven-install-plugin.version>
        <maven-clean-plugin.version>2.5</maven-clean-plugin.version>
        <maven-antrun-plugin.version>1.7</maven-antrun-plugin.version>
        <maven-dependency-plugin.version>2.5.1</maven-dependency-plugin.version>
        <maven-source-plugin.version>2.2.1</maven-source-plugin.version>
        <!--外掛版本變數 end-->

        <!--其他變數 start-->
        <war-name.version>ssm</war-name.version>
        <jdk.version>1.7</jdk.version>

        <tomcat-port.version>8080</tomcat-port.version>
        <tomcat-uri-encoding.version>UTF-8</tomcat-uri-encoding.version>
        <tomcat-path.version>/</tomcat-path.version>
        <jetty-port.version>8080</jetty-port.version>
        <jetty-path.version>/</jetty-path.version>
        <!--其他變數 end-->

        <!--這個配置是為了解決下面兩個警告-->
        <!--Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!-->
        <!--File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!-->
        <!--指定Maven用什麼編碼來讀取原始碼及文件-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!--指定Maven用什麼編碼來呈現站點的HTML檔案-->
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
    <!--版本變數設定 end-->

1.2 外掛設定

<build>
        <finalName>${project.artifactId}</finalName>
        <pluginManagement>
            <plugins>
                <!-- Compiler 外掛, 設定JDK版本 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <source>${jdk.version}</source>
                        <target>${jdk.version}</target>
                        <encoding>UTF-8</encoding>
                        <showWarnings>true</showWarnings>
                    </configuration>
                </plugin>
                <!-- war 打包外掛, 設定war包名稱不帶版本號 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>${maven-war-plugin.version}</version>
                    <configuration>
                        <warName>${war-name.version}</warName>
                    </configuration>
                </plugin>
                <!-- tomcat6外掛 -->
                <!--https://tomcat.apache.org/maven-plugin-2.0/tomcat6-maven-plugin/run-mojo.html-->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat6-maven-plugin</artifactId>
                    <version>${tomcat6-maven-plugin.version}</version>
                    <configuration>
                        <!--專案訪問路徑 這裡直接使用根目錄就可以了,訪問地址http://localhost:8080/ -->
                        <!-- 如果這裡配置了,比如test,那訪問地址就需要變成:http://localhost:8080/test-->
                        <path>${tomcat-path.version}</path>
                        <port>${tomcat-port.version}</port>
                        <!--tomcat的url編碼  達到和修改server.xml檔案一樣的功能-->
                        <uriEncoding>${tomcat-uri-encoding.version}</uriEncoding>
                        <!--配置遠端tomcat管理的連線路徑地址(固定的一個連結)-->
                        <url>http://localhost:8080/manager/html</url>
                        <server>tomcat6</server>
                    </configuration>
                </plugin>
                <!--tomcat7外掛-->
                <!--https://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/run-mojo.html-->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>${tomcat7-maven-plugin.version}</version>
                    <configuration>
                        <path>${tomcat-path.version}</path>
                        <port>${tomcat-port.version}</port>
                        <uriEncoding>${tomcat-uri-encoding.version}</uriEncoding>
                        <url>http://localhost:8080/manager/text</url>
                        <server>tomcat7</server>
                        <username>admin</username>
                        <password>admin</password>
                    </configuration>
                </plugin>
                <!--jetty外掛-->
                <!--http://www.eclipse.org/jetty/documentation/9.0.0.M3/jetty-maven-plugin.html-->
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>${jetty-plugin.version}</version>
                    <configuration>
                        <stopKey>foo</stopKey>
                        <stopPort>9999</stopPort>
                        <connectors>
                            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                                <port>${jetty-port.version}</port>
                            </connector>
                        </connectors>
                        <webApp>
                            <!--訪問地址:http://localhost:8080/index.jsp-->
                            <!--如果不帶index.jsp會直接報404,這個一直沒找到原因-->
                            <contextPath>${jetty-path.version}</contextPath>
                        </webApp>
                        <!--scanIntervalSeconds 可選[秒]。在很短的時間間隔內在掃描web應用檢查是否有改變,如果發覺有任何改變則自動熱部署。預設為0,表示禁用熱部署檢查。任何一個大於0的數字都將表示啟用。-->
                        <scanIntervalSeconds>10</scanIntervalSeconds>
                    </configuration>
                </plugin>
                <!-- resource外掛 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>${maven-resources-plugin.version}</version>
                </plugin>
                <!-- source外掛 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>${maven-source-plugin.version}</version>
                </plugin>
                <!-- install外掛 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>${maven-install-plugin.version}</version>
                </plugin>
                <!-- clean外掛 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>${maven-clean-plugin.version}</version>
                </plugin>
                <!-- ant外掛 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>${maven-antrun-plugin.version}</version>
                </plugin>
                <!-- dependency外掛 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>${maven-dependency-plugin.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

摘自www.youmeek.com.

相關文章