💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
案例代码:https://gitee.com/flymini/codes02/tree/master/maven_plugins_/com-learn-plugin02 **** appassembler-maven-plugin 可以为 Java 项目自动生成启动脚本,但是做不到将生成的资源打包成压缩包,需要配合插件 maven-assembly-plugin 才能做到。 <br/> 步骤如下: **1. pom 中引入两个插件** ```xml <build> <plugins> <!-- spring-boot-maven-plugin插件与appassembler-maven-plugin插件不兼容,不要将spring-boot-maven-plugin插件引进来 --> <!-- <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>appassembler-maven-plugin</artifactId> <version>2.1.0</version> <configuration> <platforms> <platform>unix</platform> <platform>windows</platform> </platforms> <!--打包后生成的target目录路径,如D:/workspace/com-learn-plugin02/target--> <assembleDirectory>${project.build.directory}/${project.name}</assembleDirectory> <!-- flat与lib共同决定将项目用的的所有jar包复制到lib目录下 --> <repositoryLayout>flat</repositoryLayout> <repositoryName>lib</repositoryName> <!--启动脚本存放在bin目录--> <binFolder>bin</binFolder> <!--配置文件存放在conf目录路径--> <configurationDirectory>conf</configurationDirectory> <!--是否copy配置文件--> <copyConfigurationDirectory>true</copyConfigurationDirectory> <!--从哪里copy配置文件--> <configurationSourceDirectory>src/main/resources</configurationSourceDirectory> <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath> <binFileExtensions> <!-- 针对不同平台生成不同类型的启动脚本 --> <unix>.sh</unix> <windows>.bat</windows> </binFileExtensions> <encoding>UTF-8</encoding> <logsDirectory>logs</logsDirectory> <tempDirectory>tmp</tempDirectory> <daemons> <daemon> <!-- 启动脚本的名称,Linux平台上就是:app,windows平台上就是app.bat --> <id>app</id> <!-- 启动类 --> <mainClass>com.learn.plugin02.Plugin02Application</mainClass> <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> </generatorConfiguration> </generatorConfigurations> <jvmSettings> <!-- 启动时的一下jvm参数配置 --> <extraArguments> <extraArgument>-server</extraArgument> <extraArgument>-Xms256M</extraArgument> <extraArgument>-Xmx256M</extraArgument> <extraArgument>-Xss512k</extraArgument> <extraArgument>-Xloggc:logs/demo_gc.log</extraArgument> <extraArgument>-verbose:gc</extraArgument> <extraArgument>-XX:+HeapDumpOnOutOfMemoryError</extraArgument> <extraArgument>-XX:HeapDumpPath=logs/java_heapdump.hprof</extraArgument> </extraArguments> </jvmSettings> </daemon> </daemons> <programs> <program> <mainClass>com.learn.plugin02.Plugin02Application</mainClass> <id>demoApp</id> </program> </programs> </configuration> <!-- 如果不配置 generate-daemons,则打包命令为 mvn clean package appassembler:generate-daemons --> <!-- 如果配置了 generate-daemons,打包命令可以是 mvn clean package 也可以是 mvn clean package appassembler:generate-daemons --> <executions> <execution> <inherited>true</inherited> <phase>package</phase> <goals> <goal>generate-daemons</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.1.0</version> <configuration> <!-- 压缩包名称 --> <finalName>${project.artifactId}</finalName> <descriptors> <descriptor>src/main/assembly/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ``` **2. `src/main/assembly/assembly.xml`** ```xml <?xml version="1.0" encoding="UTF-8"?> <assembly> <id>${project.version}</id> <formats> <format>tar.gz</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <fileSets> <!-- 将appassembler插件生成的资源输出到压缩包的根目录下 --> <fileSet> <directory>${basedir}/target/generated-resources/appassembler/jsw/app/</directory> <outputDirectory>/</outputDirectory> <fileMode>0777</fileMode> </fileSet> </fileSets> </assembly> ``` **3. 执行`mvn clean package`打包** **4. 生成的压缩包及其目录结构** ``` 压缩包:target/com-learn-plugin02-1.0-SNAPSHOT.tar.gz 压缩包目录结构如下: |—— com-learn-boot14 | |—— bin | | |—— app | | |—— app.bat | | |—— wrapper-linux-x86-32 | | |—— wrapper-linux-x86-64 | | |—— wrapper-linux-x86-32.exe | | |—— wrapper-linux-x86-64.exe | |—— conf | | |—— application.yml | | |—— wrapper.conf | |—— lib | | |—— ..jar | |—— logs | |—— tmp ```