Eee_xiang

导航

Maven 打包项目 部署到服务器 重启服务 插件

1、maven插件wagon-maven-plugin自动部署远程Linux服务器  (http://xxgblog.com/2015/10/23/wagon-maven-plugin/)

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>wagon-maven-plugin</artifactId>
                <version>1.0</version>
                <configuration>
                    <fromFile>executableJar/${final.name}.jar</fromFile>
                    <url>scp://${user}:${password}@${ip}/data/app/uploadDir</url>
                    <commands>
                        <!--<command>/etc/init.d/nginx stop</command>-->
                        <command>cp /data/app/${final.name}.jar /data/app/uploadDir/${final.name}.jar_`date "+%Y-%m-%d_%H-%M-%S"`</command>
                        <command>sh /data/app/diary-starter.sh stop</command>
                        <command>mv -f /data/app/uploadDir/${final.name}.jar /data/app/${final.name}.jar</command>
                        <command>sh /data/app/diary-starter.sh restart</command>
                        <!--<command>/etc/init.d/nginx start</command>-->
                    </commands>
                    <displayCommandOutputs>true</displayCommandOutputs>
                </configuration>
            </plugin>

2、maven插件maven-resources-plugin 设置加载资源文件的时候占位符是否需要被替换

 

  要用到<resource/>标签和maven-resources-plugin插件了,用法如下:

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>application.properties</exclude>
                    <exclude>application-prod.properties</exclude>
                    <exclude>application-test.properties</exclude>
                    <!--<exclude>application-remoteTest.properties</exclude>-->
                    <!--<exclude>application-remoteProd.properties</exclude>-->
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>application.properties</include>
                    <include>application-${profileActive}.properties</include>
                </includes>
            </resource>
        </resources>
        <finalName>../executableJar/${final.name}</finalName>

  resource的filtering属性用来表示资源文件中的占位符是否需要被替换,true为需要替换

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>

 以上<nonfilteredFileExtension>作用:maven打包时,会编译特定文件使得文件不可用。用上面的方法可以排除某些文件不编译

posted on 2019-01-11 18:47  Eee_xiang  阅读(903)  评论(0编辑  收藏  举报