转自:https://blog.csdn.net/baidu_32078207/article/details/98937361
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/baidu_32078207/article/details/98937361
SpringBoot快速打包注册服务之appassembler教程+绕坑
片头:本片所有内容均来自网上和工作上的整理希望后来人少走弯路
背景:用springBoot开发结束会须需要打包发布,当服务多的时候不宜管理,我们注册成服务就好看多了,也节省效率,节约时间少掉头发。
适用范围:SpringBoot+maven
结果展示
废话不罗嗦最后一首歌
这是必要的pom配置所有pom都要加!你滴明白
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<!-- Specify the configuration files that do not need to be packaged into the jar package -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- The exclusion rule is recommended to be consistent with the import rules in the assembly.xml file -->
<excludes>
<!--把src/main/resources目录下一些属性配置文件不用打到jar包中的文件剔除 -->
<!-- Custom configuration -->
<exclude>*.yml</exclude>
<exclude>*.xml</exclude>
<exclude>*.properties</exclude>
<exclude>static/**</exclude>
<!-- Must be configured -->
<exclude>*.conf</exclude>
<exclude>tools/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-command</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<outputDirectory>${project.build.directory}/config</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/config</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resource</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<outputDirectory>target/ext</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>disconf.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-static</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<outputDirectory>${project.build.directory}/static</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources/static</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Use enforcer to mandatory agreement rule: mvn validate -->
<!-- mvn clean install -Denforcer.skip=true -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce</id>
<configuration>
<rules>
<dependencyConvergence/>
</rules>
</configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Packing command: mvn clean package appassembler:generate-daemons -Dmaven.test.skip=true -->
<!-- Using JSW services to create scaffolding for target material packages -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<encoding>UTF-8</encoding>
<binFolder>bin</binFolder>
<!--ext是 扩展目录,classpath方式引用的属性文件,打包完后放置在该目录下就能读取到 -->
<extDirectory>ext</extDirectory>
<tempDirectory>temp</tempDirectory>
<logsDirectory>logs</logsDirectory>
<repositoryName>lib</repositoryName>
<repositoryLayout>flat</repositoryLayout>
<target>${project.build.directory}/dist</target>
<configurationDirectory>config</configurationDirectory>
<copyConfigurationDirectory>true</copyConfigurationDirectory>
<configurationSourceDirectory>config</configurationSourceDirectory>
<binFileExtensions>
<unix>.sh</unix>
</binFileExtensions>
<platforms>
<platform>windows</platform>
<platform>unix</platform>
</platforms>
<daemons>
<daemon>
<!--<appName>${artifactId}</appName>-->
<id>${artifactId}</id>
<!-- Main Class 根据不同项目填写实际类-->
<mainClass>com.djhu.DemoApplication</mainClass> <platforms>
<!-- Java Service Wrapper -->
<platform>jsw</platform>
</platforms>
<generatorConfigurations>
<generatorConfiguration>
<generator>jsw</generator>
<includes>
<!-- <include>aix-ppc-32</include>
<include>aix-ppc-64</include>
<include>linux-ppc-64</include>
<include>linux-x86-32</include>-->
<include>linux-x86-64</include>
<include>windows-x86-64</include>
<!--
<include>windows-x86-32</include>
<include>hpux-parisc-64</include>
<include>solaris-x86-32</include>
<include>solaris-sparc-32</include>
<include>solaris-sparc-64</include>
<include>macosx-ppc-32</include>
<include>macosx-universal-32</include>
<include>macosx-universal-64</include> -->
</includes>
<configuration>
<property>
<name>app.base.envvar</name>
<value>BASEDIR</value>
</property>
<property>
<name>configuration.directory.in.config</name>
<value>config</value>
</property>
<property>
<name>wrapper.ping.timeout</name>
<value>120</value>
</property>
<!-- 指定配置文件目录 -->
<property>
<name>configuration.directory.in.classpath.first</name>
<value>ext</value>
</property>
<property>
<name>set.default.REPO_DIR</name>
<value>lib</value>
</property>
<property>
<name>wrapper.logfile</name>
<value>logs/wrapper.log</value>
</property>
</configuration>
</generatorConfiguration>
</generatorConfigurations>
<jvmSettings>
<systemProperties>
<systemProperty>appserver.home=.</systemProperty>
<systemProperty>appserver.base=%BASEDIR%</systemProperty>
<systemProperty>java.io.tmpdir=temp</systemProperty>
</systemProperties>
<!-- JMX -->
<!--
<systemProperties>
<systemProperty>java.security.policy=conf/policy.all</systemProperty>
<systemProperty>com.sun.management.jmxremote</systemProperty>
<systemProperty>com.sun.management.jmxremote.port=8777</systemProperty>
<systemProperty>com.sun.management.jmxremote.authenticate=false</systemProperty>
<systemProperty>com.sun.management.jmxremote.ssl=false</systemProperty>
</systemProperties>
-->
<extraArguments>
<extraArgument>-server</extraArgument>
<!-- Remote Debug -->
<extraArgument>-Xdebug</extraArgument>
<!--
<extraArgument>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5010</extraArgument>
-->
<!-- Heap Dump -->
<extraArgument>-XX:+HeapDumpOnOutOfMemoryError</extraArgument>
<extraArgument>-XX:HeapDumpPath=logs/heap-dump.hprof</extraArgument>
<!-- GC Config -->
<extraArgument>-XX:+UseG1GC</extraArgument>
<extraArgument>-XX:MaxGCPauseMillis=200</extraArgument>
<extraArgument>-XX:InitiatingHeapOccupancyPercent=45</extraArgument>
<extraArgument>-XX:G1ReservePercent=10</extraArgument>
<extraArgument>-XX:NewRatio=2</extraArgument>
<extraArgument>-XX:SurvivorRatio=8</extraArgument>
<extraArgument>-XX:MaxTenuringThreshold=15</extraArgument>
<!-- GC Log -->
<extraArgument>-Xloggc:logs/gc.log</extraArgument>
<extraArgument>-XX:GCLogFileSize=10M</extraArgument>
<extraArgument>-XX:NumberOfGCLogFiles=10</extraArgument>
<extraArgument>-XX:+UseGCLogFileRotation</extraArgument>
<extraArgument>-XX:+PrintGCDateStamps</extraArgument>
<extraArgument>-XX:+PrintGCTimeStamps</extraArgument>
<extraArgument>-XX:+PrintGCDetails</extraArgument>
<extraArgument>-XX:+PrintHeapAtGC</extraArgument>
<extraArgument>-XX:+PrintGCApplicationStoppedTime</extraArgument>
<extraArgument>-XX:+DisableExplicitGC</extraArgument>
<extraArgument>-verbose:gc</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>
<!-- Use assembly to package the scaffolding directory into compressed packets -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<encoding>UTF-8</encoding>
<appendAssemblyId>false</appendAssemblyId>
<!-- 注意这里的版本号,每次发布时候需要修改此处版本号 -->
<finalName>${artifactId}_v2.0.0.2_${timestamp}</finalName>
<descriptors>
<!-- 注意:在src/main/resouces 目录下必须要有package.xml -->
<descriptor>src/main/resources/package.xml</descriptor> </descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<timestampFormat>yyyyMMdd</timestampFormat>
</configuration>
<executions>
<execution>
<goals>
<goal>create-timestamp</goal>
</goals>
</execution>
</executions>
<inherited>false</inherited>
</plugin>
然后一个配置文件
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0
http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>target/ext</directory>
<outputDirectory>ext</outputDirectory>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
</fileSet>
<fileSet>
<directory>target/dist/jsw/${artifactId}/bin</directory>
<outputDirectory>bin</outputDirectory>
<!-- Set executable permissions -->
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
</fileSet>
<fileSet>
<directory>target/dist/jsw/${artifactId}/config/tools</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<includes>
<include>**.sh</include>
<include>**.bat</include>
</includes>
</fileSet>
<fileSet>
<directory>target/dist/jsw/${artifactId}/config</directory>
<outputDirectory>config</outputDirectory>
<!-- The import rules here recommend consistency with exclusionary rules in the pom.xml file -->
<includes>
<!-- Custom configuration -->
<include>*.yml</include>
<include>*.xml</include>
<include>*.properties</include>
<include>static/**</include>
<!-- Must be configured -->
<include>*.conf</include>
<include>*.json</include>
</includes>
<excludes>
<!-- Must be configured -->
<exclude>tools/**</exclude>
</excludes>
<fileMode>0644</fileMode>
<directoryMode>0744</directoryMode>
</fileSet>
<fileSet>
<directory>target/dist/jsw/${artifactId}/lib</directory>
<outputDirectory>lib</outputDirectory>
<fileMode>0644</fileMode>
<directoryMode>0744</directoryMode>
</fileSet>
<fileSet>
<directory>target/dist/jsw/${artifactId}/logs</directory>
<outputDirectory>logs</outputDirectory>
<fileMode>0644</fileMode>
<directoryMode>0744</directoryMode>
</fileSet>
<fileSet>
<directory>target/dist/jsw/${artifactId}/temp</directory>
<outputDirectory>temp</outputDirectory>
<fileMode>0644</fileMode>
<directoryMode>0744</directoryMode>
</fileSet>
</fileSets>
</assembly>
这就完成啦!no no no no
有坑
1.绿色框注的是一些配置文件但是
你的配置文件里有“classpath:”这种的不能从配置文件摘除里拿出来否则的话会报错N个注入失败或者改成classpath:*
你把这个节点includes去掉的话就可以把所有的resources文件都露出来了但是不行,一般都会有mybatis的配置文件会找不到XML然后提示注入失败,那有的人问了,我想把一些模板类型文件展现出来实施有时候需要修改,或者其他需要怎么办!ok
这个节点改个 ID 然后文件路径注意下就可以了,很简单的
2不能有强调springBoot要这么用否则回有“找不到主类”
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.7.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
明白了么
3剩余的也就没什么了,还是比较简单的就是配置文件有点头疼再就是注册才能启动否则启动不了
4最后奉上资源(没办法最便宜的也要5分)
https://download.csdn.net/download/baidu_32078207/11505255
最后一句话
你眸光流转,会心一笑,胜过千万句对白;你真情传递,脉脉不语,胜过万语千言
————————————————
版权声明:本文为CSDN博主「巧克力牌猫头鹰」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/baidu_32078207/article/details/98937361