使用appassembler-maven-plugin插件生成启动脚本

appassembler-maven-plugin可以自动生成跨平台的启动脚本,省去了手工写脚本的麻烦,而且还可以生成jsw的后台运行程序。

首先pom引入相关依赖

     <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${java.src.version}</source>
                    <target>${java.target.version}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.bosssoft.platform.appframe.mobile.TestAuth</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
    <profile>
        <id>appassembler</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <!-- Generate both Windows and Linux bash shell execution scripts -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>appassembler-maven-plugin</artifactId>
                    <version>1.10</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>assemble</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <repositoryLayout>flat</repositoryLayout>
                        <useWildcardClassPath>true</useWildcardClassPath>
                        <!-- Set the target configuration directory to be used in the bin scripts -->
                        <configurationDirectory>conf</configurationDirectory>
                        <!-- Copy the contents from "/src/main/config" to the target configuration
                            directory in the assembled application -->
                        <copyConfigurationDirectory>true</copyConfigurationDirectory>
                        <!-- Include the target configuration directory in the beginning of
                            the classpath declaration in the bin scripts -->
                        <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
                        <!-- Extra JVM arguments that will be included in the bin scripts -->
                        <repositoryName>lib</repositoryName>
                        <extraJvmArguments>-Xmx1024m -Djava.net.preferIPv4Stack=true -Dfile.encoding=utf-8</extraJvmArguments>
                        <programs>
                            <program>
                                <id>main</id>
                                <mainClass>com.bosssoft.platform.appframe.mobile.TestAuth</mainClass>
                                <name>main</name>
                            </program>
                        </programs>
                        <binFileExtensions>
                            <unix>.sh</unix>
                        </binFileExtensions>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    </profiles>

注:红色标注的内容改成,main所在的程序类路径

然后运行maven命令 :mvn package appassembler:assemble 或者mvn clean install即可

就可以自动生成整个的依赖文件,配置文件和运行脚本了。

相关配置说明:

configurationDirectory:生成配置文件路径
configurationSourceDirectory:配置文件原路径,默认为src/main/config
assembleDirectory:整体包目录
extraJvmArguments:jvm参数
binFileExtensions:生成脚本的后缀
platforms:生成哪几种平台
repositoryName:依赖包目录,默认repo
programs:这个必须参数,启动的主class 
posted @ 2018-03-15 09:20  shawWey  阅读(4004)  评论(1编辑  收藏  举报