appassembler-maven-plugin插件的作用以及使用
appassembler-maven-plugin可以自动生成跨平台的启动脚本,省去了手工写脚本的麻烦,而且还可以生成jsw的后台运行程序。appassembler的配置比较简单,在pom.xml的配置文件加入插件配置。
pom中配置
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.10</version>
<configuration>
<configurationDirectory>conf</configurationDirectory>
<configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
<copyConfigurationDirectory>true</copyConfigurationDirectory>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
<assembleDirectory>${project.build.directory}/app</assembleDirectory>
<extraJvmArguments>-Xms128m</extraJvmArguments>
<binFileExtensions>
<unix>.sh</unix>
</binFileExtensions>
<platforms>
<platform>windows</platform>
<platform>unix</platform>
</platforms>
<repositoryName>lib</repositoryName>
<programs>
<program>
<id>app</id>
<mainClass>com.app.Main</mainClass>
<jvmSettings>
<extraArguments>
<extraArgument>-server </extraArgument>
<extraArgument>-Xmx2G</extraArgument>
<extraArgument>-Xms2G</extraArgument>
</extraArguments>
</jvmSettings>
</program>
</programs>
</configuration>
</plugin>
maven命令
mvn package appassembler:assemble
这样子就可以自动生成整个依赖文件,配置文件和运行脚本了。
配置说明
- configurationDirectory:生成配置文件路径
- configurationSourceDirectory:配置文件原路径,默认为src/main/config
- assembleDirectory:整体包目录
- extraJvmArguments:jvm参数
- binFileExtensions:生成脚本的后缀
- platforms:生成哪几种平台
- repositoryName:依赖包目录,默认repo
- programs:这个必须参数,启动的主class
jsw生成
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<repositoryLayout>flat</repositoryLayout>
<repositoryName>lib</repositoryName>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
<copyConfigurationDirectory>src/main/resources</copyConfigurationDirectory>
<target>${project.build.directory}</target>
<daemons>
<daemon>
<id>client</id>
<mainClass>com.demo.client.App</mainClass>
<commandLineArguments>
<commandLineArgument>start</commandLineArgument>
</commandLineArguments>
<platforms>
<platform>jsw</platform>
</platforms>
<generatorConfigurations>
<generatorConfiguration>
<generator>jsw</generator>
<includes>
<include>linux-x86-32</include>
<include>linux-x86-64</include>
<include>windows-x86-32</include>
<include>windows-x86-64</include>
</includes>
<configuration>
<property>
<name>configuration.directory.in.classpath.first</name>
<value>etc</value>
</property>
<property>
<name>set.default.REPO_DIR</name>
<value>lib</value>
</property>
<property>
<name>wrapper.logfile</name>
<value>../logs/wrapper.log</value>
</property>
<property>
<name>run.as.user.envvar</name>
<value>johndoe</value>
</property>
</configuration>
</generatorConfiguration>
</generatorConfigurations>
<jvmSettings>
<initialMemorySize>256M</initialMemorySize>
<maxMemorySize>512M</maxMemorySize>
<systemProperties>
<systemProperty>java.security.policy=conf/policy.all</systemProperty>
<systemProperty>com.sun.management.jmxremote</systemProperty>
<systemProperty>com.sun.management.jmxremote.port=8999</systemProperty>
<systemProperty>com.sun.management.jmxremote.authenticate=false</systemProperty>
<systemProperty>com.sun.management.jmxremote.ssl=false</systemProperty>
</systemProperties>
<extraArguments>
<extraArgument>-server</extraArgument>
</extraArguments>
</jvmSettings>
</daemon>
</daemons>
</configuration>
<executions>
<execution>
<id>generate-jsw-scripts</id>
<phase>package</phase>
<goals>
<goal>generate-daemons</goal>
</goals>
</execution>
</executions>
</plugin>