概览
通过配置maven插件,可以快速集成launcher
启动器功能,接入简单快捷
添加maven配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 <project > [...] <build > [...] <plugins > [...] <plugin > <groupId > org.gy.framework</groupId > <artifactId > launcher-maven-plugin</artifactId > <version > 1.0.0-SNAPSHOT</version > <executions > <execution > <goals > <goal > launcher</goal > </goals > <configuration > </configuration > </execution > </executions > </plugin > [...] </plugins > [...] </build > [...] </project >
应用基础配置 在插件中配置 应用名称
跟 MainClass
的对应关系,应用启动时可以直接通过 -n ${APP_NAME}
启动该应用
1 2 3 4 5 6 7 8 9 <configuration > <app > <name > ${APP_NAME}</name > <mainClass > ${APP_MAIN_CLASS}</mainClass > </app > </configuration >
修改默认日志级别 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 <plugin > <groupId > org.gy.framework</groupId > <artifactId > launcher-maven-plugin</artifactId > <version > 1.0.0-SNAPSHOT</version > <executions > <execution > <goals > <goal > launcher</goal > </goals > <configuration > <log > <logName > org.gy.framework</logName > <logLevel > DEBUG</logLevel > <rootLogLevel > ERROR</rootLogLevel > <logFileSize > 1024</logFileSize > <logFileCount > 5</logFileCount > </log > </configuration > </execution > </executions > </plugin >
追加maven-assembly-plugin配置 launcher-maven-plugin
允许用户将某些文件放入最终的应用打包文件中
1 2 3 4 <configuration > <fileSet > package.xml</fileSet > </configuration >
示例 将工程中的 ./src/main/resources/my-app.config
放到打包结果中的 conf
目录下
编写 maven-assembly-plugin
的配置文件 package.xml
1 2 3 4 5 6 7 8 <fileSet > <directory > ./src/main/resources</directory > <includes > <include > my-app.config</include > </includes > <outputDirectory > conf</outputDirectory > <lineEnding > unix</lineEnding > </fileSet >
目前仅支持 maven-assembly-plugin
配置中的 <fileSet>
片段
访问 http://maven.apache.org/plugins/maven-assembly-plugin
了解更多关于 <fileSet>
的使用方法
默认JVM参数修改 launcher
提供了一系列标准的JVM默认参数
并且提供了修改这些默认参数的方法,减少在启动时输入带来的复杂度
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <configuration > <app > <name > ${APP_NAME}</name > <mainClass > ${APP_MAIN_CLASS}</mainClass > <jvmOption > <include > -Dapp.test1=1 -Dapp.test2=2 </include > <exclude > -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles -XX:GCLogFileSize </exclude > </jvmOption > </app > </configuration >
打包完成后,在 ./conf
目录下会生成一个 ${APP_NAME}.jvm.options
文件其中包含已修改的配置
If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !