使用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 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM