{"id":21281135,"url":"https://github.com/geekidea/spring-boot-assembly","last_synced_at":"2025-04-07T10:28:28.610Z","repository":{"id":49523680,"uuid":"162861508","full_name":"geekidea/spring-boot-assembly","owner":"geekidea","description":"Spring Boot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip","archived":false,"fork":false,"pushed_at":"2023-12-16T17:23:33.000Z","size":62,"stargazers_count":215,"open_issues_count":9,"forks_count":112,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-31T08:12:24.263Z","etag":null,"topics":["maven-assembly-plugin","maven-dependency-plugin","maven-jar-plugin","maven-resources-plugin","spring-boot-maven-plugin","springboot2"],"latest_commit_sha":null,"homepage":"https://geekidea.io/spring-boot-assembly/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geekidea.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-23T04:14:52.000Z","updated_at":"2025-02-07T14:51:45.000Z","dependencies_parsed_at":"2024-12-24T11:12:59.160Z","dependency_job_id":"ac50b208-3d7d-44f3-8f64-a43a85c9065b","html_url":"https://github.com/geekidea/spring-boot-assembly","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geekidea%2Fspring-boot-assembly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geekidea%2Fspring-boot-assembly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geekidea%2Fspring-boot-assembly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geekidea%2Fspring-boot-assembly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geekidea","download_url":"https://codeload.github.com/geekidea/spring-boot-assembly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247634898,"owners_count":20970628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["maven-assembly-plugin","maven-dependency-plugin","maven-jar-plugin","maven-resources-plugin","spring-boot-maven-plugin","springboot2"],"created_at":"2024-11-21T10:45:15.616Z","updated_at":"2025-04-07T10:28:28.582Z","avatar_url":"https://github.com/geekidea.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spring-boot-assembly\n\n\u003e 1. 在spring boot项目中使用maven profiles和maven assembly插件根据不同环境打包成tar.gz或者zip\n\u003e 2. 将spring boot项目中的配置文件提取到外部config目录中\n\u003e 3. 将spring boot项目中的启动jar包移动到boot目录中\n\u003e 4. 将spring boot项目中的第三方依赖jar包移动到外部lib目录中\n\u003e 5. bin目录中是启动，停止，重启服务命令\n\u003e 6. 打包后的目录结构类似于tomcat/maven目录结构\n\n## 代码托管\n\n\u003e **[Github](https://github.com/geekidea/spring-boot-assembly)** | **[Gitee](https://gitee.com/geekidea/spring-boot-assembly)**\n\n\n### 主要插件\n1. maven-assembly-plugin\n2. maven-jar-plugin\n3. spring-boot-maven-plugin\n4. maven-dependency-plugin\n5. maven-resources-plugin\n\n### CHANGELOG\n[CHANGELOG](https://github.com/geekidea/spring-boot-assembly/blob/master/CHANGELOG.md)\n\n#### 1.maven-assembly-plugin 配置assembly.xml文件路径\n```xml\n\u003cplugin\u003e\n        \u003cartifactId\u003emaven-assembly-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e3.1.0\u003c/version\u003e\n        \u003cconfiguration\u003e\n            \u003cdescriptors\u003e\n                \u003cdescriptor\u003esrc/main/assembly/assembly.xml\u003c/descriptor\u003e\n            \u003c/descriptors\u003e\n        \u003c/configuration\u003e\n        \u003cexecutions\u003e\n            \u003cexecution\u003e\n                \u003cid\u003emake-assembly\u003c/id\u003e\n                \u003cphase\u003epackage\u003c/phase\u003e\n                \u003cgoals\u003e\n                    \u003cgoal\u003esingle\u003c/goal\u003e\n                \u003c/goals\u003e\n            \u003c/execution\u003e\n        \u003c/executions\u003e\n    \u003c/plugin\u003e\n```\n    \n#### 2.assembly.xml打包配置文件\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cassembly\u003e\n    \u003c!-- 可自定义，这里指定的是项目环境 --\u003e\n    \u003c!-- spring-boot-assembly-local-1.0.RELEASE.tar.gz  --\u003e\n    \u003cid\u003e${profileActive}-${project.version}\u003c/id\u003e\n\n    \u003c!-- 打包的类型，如果有N个，将会打N个类型的包 --\u003e\n    \u003cformats\u003e\n        \u003cformat\u003etar.gz\u003c/format\u003e\n        \u003c!--\u003cformat\u003ezip\u003c/format\u003e--\u003e\n    \u003c/formats\u003e\n\n    \u003cincludeBaseDirectory\u003etrue\u003c/includeBaseDirectory\u003e\n\n    \u003cfileSets\u003e\n        \u003c!--\n            0755-\u003e即用户具有读/写/执行权限，组用户和其它用户具有读写权限；\n            0644-\u003e即用户具有读写权限，组用户和其它用户具有只读权限；\n        --\u003e\n        \u003c!-- 将src/bin目录下的所有文件输出到打包后的bin目录中 --\u003e\n        \u003cfileSet\u003e\n            \u003cdirectory\u003e${basedir}/src/bin\u003c/directory\u003e\n            \u003coutputDirectory\u003ebin\u003c/outputDirectory\u003e\n            \u003cfileMode\u003e0755\u003c/fileMode\u003e\n            \u003cincludes\u003e\n                \u003cinclude\u003e**.sh\u003c/include\u003e\n                \u003cinclude\u003e**.bat\u003c/include\u003e\n            \u003c/includes\u003e\n        \u003c/fileSet\u003e\n\n        \u003c!-- 指定输出target/classes中的配置文件到config目录中 --\u003e\n        \u003cfileSet\u003e\n            \u003cdirectory\u003e${basedir}/target/classes\u003c/directory\u003e\n            \u003coutputDirectory\u003econfig\u003c/outputDirectory\u003e\n            \u003cfileMode\u003e0644\u003c/fileMode\u003e\n            \u003cincludes\u003e\n                \u003cinclude\u003eapplication.yml\u003c/include\u003e\n                \u003cinclude\u003eapplication-${profileActive}.yml\u003c/include\u003e\n                \u003cinclude\u003emapper/**/*.xml\u003c/include\u003e\n                \u003cinclude\u003estatic/**\u003c/include\u003e\n                \u003cinclude\u003etemplates/**\u003c/include\u003e\n                \u003cinclude\u003e*.xml\u003c/include\u003e\n                \u003cinclude\u003e*.properties\u003c/include\u003e\n            \u003c/includes\u003e\n        \u003c/fileSet\u003e\n\n        \u003c!-- 将第三方依赖打包到lib目录中 --\u003e\n        \u003cfileSet\u003e\n            \u003cdirectory\u003e${basedir}/target/lib\u003c/directory\u003e\n            \u003coutputDirectory\u003elib\u003c/outputDirectory\u003e\n            \u003cfileMode\u003e0755\u003c/fileMode\u003e\n        \u003c/fileSet\u003e\n\n        \u003c!-- 将项目启动jar打包到boot目录中 --\u003e\n        \u003cfileSet\u003e\n            \u003cdirectory\u003e${basedir}/target\u003c/directory\u003e\n            \u003coutputDirectory\u003eboot\u003c/outputDirectory\u003e\n            \u003cfileMode\u003e0755\u003c/fileMode\u003e\n            \u003cincludes\u003e\n                \u003cinclude\u003e${project.build.finalName}.jar\u003c/include\u003e\n            \u003c/includes\u003e\n        \u003c/fileSet\u003e\n\n        \u003c!-- 包含根目录下的文件 --\u003e\n        \u003cfileSet\u003e\n            \u003cdirectory\u003e${basedir}\u003c/directory\u003e\n            \u003cincludes\u003e\n                \u003cinclude\u003eNOTICE\u003c/include\u003e\n                \u003cinclude\u003eLICENSE\u003c/include\u003e\n                \u003cinclude\u003e*.md\u003c/include\u003e\n            \u003c/includes\u003e\n        \u003c/fileSet\u003e\n    \u003c/fileSets\u003e\n\n\u003c/assembly\u003e\n```\n\n#### 3.spring-boot-maven-plugin 排除启动jar包中依赖的jar包\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n    \u003cartifactId\u003espring-boot-maven-plugin\u003c/artifactId\u003e\n    \u003cconfiguration\u003e\n        \u003clayout\u003eZIP\u003c/layout\u003e\n        \u003cincludes\u003e\n            \u003c!-- 项目启动jar包中排除依赖包 --\u003e\n            \u003cinclude\u003e\n                \u003cgroupId\u003enon-exists\u003c/groupId\u003e\n                \u003cartifactId\u003enon-exists\u003c/artifactId\u003e\n            \u003c/include\u003e\n        \u003c/includes\u003e\n    \u003c/configuration\u003e\n\u003c/plugin\u003e\n```\n\n#### 4.maven-jar-plugin 自定义maven jar打包内容\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n    \u003cartifactId\u003emaven-jar-plugin\u003c/artifactId\u003e\n    \u003cversion\u003e3.1.0\u003c/version\u003e\n    \u003cconfiguration\u003e\n        \u003carchive\u003e\n            \u003cmanifest\u003e\n                \u003c!-- 项目启动类 --\u003e\n                \u003cmainClass\u003eApplication\u003c/mainClass\u003e\n                \u003c!-- 依赖的jar的目录前缀 --\u003e\n                \u003cclasspathPrefix\u003e../lib\u003c/classpathPrefix\u003e\n                \u003caddClasspath\u003etrue\u003c/addClasspath\u003e\n            \u003c/manifest\u003e\n        \u003c/archive\u003e\n        \u003cincludes\u003e\n            \u003c!-- 只打包指定目录的文件 --\u003e\n            \u003cinclude\u003eio/geekidea/springboot/**\u003c/include\u003e\n        \u003c/includes\u003e\n    \u003c/configuration\u003e\n\u003c/plugin\u003e    \n```\n    \n#### 5.maven-dependency-plugin 复制项目的依赖包到指定目录\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n    \u003cartifactId\u003emaven-dependency-plugin\u003c/artifactId\u003e\n    \u003cversion\u003e3.1.0\u003c/version\u003e\n    \u003cexecutions\u003e\n        \u003cexecution\u003e\n            \u003cphase\u003eprepare-package\u003c/phase\u003e\n            \u003cgoals\u003e\n                \u003cgoal\u003ecopy-dependencies\u003c/goal\u003e\n            \u003c/goals\u003e\n            \u003cconfiguration\u003e\n                \u003coutputDirectory\u003etarget/lib\u003c/outputDirectory\u003e\n                \u003coverWriteReleases\u003efalse\u003c/overWriteReleases\u003e\n                \u003coverWriteSnapshots\u003efalse\u003c/overWriteSnapshots\u003e\n                \u003coverWriteIfNewer\u003etrue\u003c/overWriteIfNewer\u003e\n                \u003cincludeScope\u003ecompile\u003c/includeScope\u003e\n            \u003c/configuration\u003e\n        \u003c/execution\u003e\n    \u003c/executions\u003e\n\u003c/plugin\u003e\n```\n\n#### 6.maven-resources-plugin\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n    \u003cartifactId\u003emaven-resources-plugin\u003c/artifactId\u003e\n    \u003cversion\u003e3.1.0\u003c/version\u003e\n\u003c/plugin\u003e\n```\n\n```xml\n\u003cresource\u003e\n    \u003cdirectory\u003esrc/main/resources\u003c/directory\u003e\n    \u003cfiltering\u003etrue\u003c/filtering\u003e\n    \u003cincludes\u003e\n        \u003cinclude\u003eapplication.yml\u003c/include\u003e\n        \u003cinclude\u003eapplication-${profileActive}.yml\u003c/include\u003e\n        \u003cinclude\u003emapper/**/*.xml\u003c/include\u003e\n        \u003cinclude\u003estatic/**\u003c/include\u003e\n        \u003cinclude\u003etemplates/**\u003c/include\u003e\n        \u003cinclude\u003e*.xml\u003c/include\u003e\n        \u003cinclude\u003e*.properties\u003c/include\u003e\n    \u003c/includes\u003e\n\u003c/resource\u003e\n```\n    \n#### 7.maven profiles配置\n```xml\n\u003c!--MAVEN打包选择运行环境--\u003e\n\u003c!-- 1:local(默认) 本地 2:dev:开发环境 3:test 4:uat 用户验收测试 5.pro:生产环境--\u003e\n\u003cprofiles\u003e\n    \u003cprofile\u003e\n        \u003cid\u003elocal\u003c/id\u003e\n        \u003cproperties\u003e\n            \u003cprofileActive\u003elocal\u003c/profileActive\u003e\n        \u003c/properties\u003e\n        \u003cactivation\u003e\n            \u003cactiveByDefault\u003etrue\u003c/activeByDefault\u003e\n        \u003c/activation\u003e\n    \u003c/profile\u003e\n    \u003cprofile\u003e\n        \u003cid\u003edev\u003c/id\u003e\n        \u003cproperties\u003e\n            \u003cprofileActive\u003edev\u003c/profileActive\u003e\n        \u003c/properties\u003e\n        \u003cactivation\u003e\n            \u003cactiveByDefault\u003efalse\u003c/activeByDefault\u003e\n        \u003c/activation\u003e\n    \u003c/profile\u003e\n    \u003cprofile\u003e\n        \u003cid\u003etest\u003c/id\u003e\n        \u003cproperties\u003e\n            \u003cprofileActive\u003etest\u003c/profileActive\u003e\n        \u003c/properties\u003e\n        \u003cactivation\u003e\n            \u003cactiveByDefault\u003efalse\u003c/activeByDefault\u003e\n        \u003c/activation\u003e\n    \u003c/profile\u003e\n    \u003cprofile\u003e\n        \u003cid\u003euat\u003c/id\u003e\n        \u003cproperties\u003e\n            \u003cprofileActive\u003euat\u003c/profileActive\u003e\n        \u003c/properties\u003e\n        \u003cactivation\u003e\n            \u003cactiveByDefault\u003efalse\u003c/activeByDefault\u003e\n        \u003c/activation\u003e\n    \u003c/profile\u003e\n    \u003cprofile\u003e\n        \u003cid\u003eprod\u003c/id\u003e\n        \u003cproperties\u003e\n            \u003cprofileActive\u003eprod\u003c/profileActive\u003e\n        \u003c/properties\u003e\n        \u003cactivation\u003e\n            \u003cactiveByDefault\u003efalse\u003c/activeByDefault\u003e\n        \u003c/activation\u003e\n    \u003c/profile\u003e\n\u003c/profiles\u003e\n```\n    \n#### 8.阿里云仓库配置\n```xml\n\u003crepositories\u003e\n    \u003c!--阿里云仓库--\u003e\n    \u003crepository\u003e\n        \u003cid\u003ealiyun\u003c/id\u003e\n        \u003curl\u003ehttp://maven.aliyun.com/nexus/content/groups/public/\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\n    \n___    \n##### 项目源码结构\n```text\n├─bin\n│      restart.sh\n│      shutdown.sh\n│      startup.bat\n│      startup.sh\n│\n├─logs\n│      springboot-assembly.log\n│\n├─main\n│  ├─assembly\n│  │      assembly.xml\n│  │\n│  ├─java\n│  │  └─io\n│  │      └─geekidea\n│  │          └─springboot\n│  │              └─assembly\n│  │                      Application.java\n│  │                      HelloController.java\n│  │                      HelloService.java\n│  │                      HelloServiceImpl.java\n│  │\n│  └─resources\n│      │  application-dev.yml\n│      │  application-local.yml\n│      │  application-prod.yml\n│      │  application-test.yml\n│      │  application-uat.yml\n│      │  application.yml\n│      │\n│      ├─mapper\n│      │  │  test.xml\n│      │  │\n│      │  └─hello\n│      │          hello.xml\n│      │\n│      ├─static\n│      │      index.html\n│      │\n│      └─templates\n│              test.txt\n│\n└─test\n```\n\n##### 项目打包\n\n```bash\nmvn clean package\n```\n\n##### 使用maven assembly插件打包local环境后的压缩包,target目录下\n```bash\nspring-boot-assembly-local-1.0.RELEASE.tar.gz\n```\n    \n##### linux解压tar.gz\n\n```bash\ntar -zxvf spring-boot-assembly-local-1.0.RELEASE.tar.gz\n```\n\n##### 解压后的目录结构\n```text\n└─spring-boot-assembly\n    │  LICENSE\n    │  NOTICE\n    │  README.md\n    │\n    ├─bin\n    │      restart.sh\n    │      shutdown.sh\n    │      startup.bat\n    │      startup.sh\n    │\n    ├─boot\n    │      spring-boot-assembly.jar\n    │\n    ├─config\n    │  │  application-local.yml\n    │  │  application.yml\n    │  │\n    │  ├─mapper\n    │  │  │  test.xml\n    │  │  │\n    │  │  └─hello\n    │  │          hello.xml\n    │  │\n    │  ├─static\n    │  │      index.html\n    │  │\n    │  └─templates\n    │          test.txt\n    │\n    └─lib\n            classmate-1.4.0.jar\n            fastjson-1.2.54.jar\n            hibernate-validator-6.0.13.Final.jar\n            jackson-annotations-2.9.0.jar\n            jackson-core-2.9.7.jar\n            jackson-databind-2.9.7.jar\n            jackson-datatype-jdk8-2.9.7.jar\n            jackson-datatype-jsr310-2.9.7.jar\n            jackson-module-parameter-names-2.9.7.jar\n            javax.annotation-api-1.3.2.jar\n            jboss-logging-3.3.2.Final.jar\n            jul-to-slf4j-1.7.25.jar\n            log4j-api-2.11.1.jar\n            log4j-to-slf4j-2.11.1.jar\n            logback-classic-1.2.3.jar\n            logback-core-1.2.3.jar\n            slf4j-api-1.7.25.jar\n            snakeyaml-1.23.jar\n            spring-aop-5.1.2.RELEASE.jar\n            spring-beans-5.1.2.RELEASE.jar\n            spring-boot-2.1.0.RELEASE.jar\n            spring-boot-autoconfigure-2.1.0.RELEASE.jar\n            spring-boot-starter-2.1.0.RELEASE.jar\n            spring-boot-starter-json-2.1.0.RELEASE.jar\n            spring-boot-starter-logging-2.1.0.RELEASE.jar\n            spring-boot-starter-tomcat-2.1.0.RELEASE.jar\n            spring-boot-starter-web-2.1.0.RELEASE.jar\n            spring-context-5.1.2.RELEASE.jar\n            spring-core-5.1.2.RELEASE.jar\n            spring-expression-5.1.2.RELEASE.jar\n            spring-jcl-5.1.2.RELEASE.jar\n            spring-web-5.1.2.RELEASE.jar\n            spring-webmvc-5.1.2.RELEASE.jar\n            tomcat-embed-core-9.0.12.jar\n            tomcat-embed-el-9.0.12.jar\n            tomcat-embed-websocket-9.0.12.jar\n            validation-api-2.0.1.Final.jar\n```\n\n\n___\n\n##### window启动,会打开浏览器，访问项目测试路径\n\n```bash\nbin/startup.bat\n```\n\u003e - 访问地址: [http://localhost:8080/example/hello?name=123](http://localhost:8080/example/hello?name=123)\n\u003e - 响应结果: \n```json\n{\"msg\":\"service hello:123\",\"code\":200}\n```\n\n##### linux启动，停止，重启\n\n```bash\nsh bin/startup.sh   启动项目\nsh bin/shutdown.sh  停止服务\nsh bin/restart.sh   重启服务\n```    \n\n##### startup.sh 脚本中的主要内容\n- 配置项目名称及项目启动jar名称，默认项目名称与启动jar名称一致\n\n```bash\nAPPLICATION=\"spring-boot-assembly\"\nAPPLICATION_JAR=\"${APPLICATION}.jar\"\n```\n\n- JAVA_OPTION配置\n\u003e - JVM Configuration\n\u003e - -Xmx256m:设置JVM最大可用内存为256m,根据项目实际情况而定，建议最小和最大设置成一样。\n\u003e - -Xms256m:设置JVM初始内存。此值可以设置与-Xmx相同,以避免每次垃圾回收完成后JVM重新分配内存\n\u003e - -Xmn512m:设置年轻代大小为512m。整个JVM内存大小=年轻代大小 + 年老代大小 + 持久代大小。持久代一般固定大小为64m,所以增大年轻代,将会减小年老代大小。此值对系统性能影响较大,Sun官方推荐配置为整个堆的3/8\n\u003e - -XX:MetaspaceSize=64m:存储class的内存大小,该值越大触发Metaspace GC的时机就越晚\n\u003e - -XX:MaxMetaspaceSize=320m:限制Metaspace增长的上限，防止因为某些情况导致Metaspace无限的使用本地内存，影响到其他程序\n\u003e - -XX:-OmitStackTraceInFastThrow:解决重复异常不打印堆栈信息问题\n\n```bash\nJAVA_OPT=\"-server -Xms256m -Xmx256m -Xmn512m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=256m\"\nJAVA_OPT=\"${JAVA_OPT} -XX:-OmitStackTraceInFastThrow\"\n```\n#### 执行启动命令：后台启动项目,并将日志输出到项目根目录下的logs文件夹下\n\n```bash\nnohup java ${JAVA_OPT} -jar ${BASE_PATH}/boot/${APPLICATION_JAR} --spring.config.location=${CONFIG_DIR} \u003e ${LOG_PATH} 2\u003e\u00261 \u0026\n```\n\n## 最终执行jar包的命令\n\n```bash\nnohup java -server -Xms256m -Xmx256m -Xmn512m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=256m -XX:-OmitStackTraceInFastThrow -jar /opt/spring-boot-assembly/boot/spring-boot-assembly.jar --spring.config.location=/opt/spring-boot-assembly/config/ \u003e /opt/spring-boot-assembly/logs/spring-boot-assembly.log 2\u003e\u00261 \u0026\n```\n\u003e - nohup：在后台运行jar包，然后将运行日志输出到指定位置\n\u003e - -server：指定JVM参数\n\u003e - -jar /opt/spring-boot-assembly/boot/spring-boot-assembly.jar：指定启动的jar包\n\u003e - 启动命令中指定的启动jar包路径，配置文件路径，日志路径都是绝对路径\n\u003e - 可在任何位置执行start.sh,shutdown.sh,restart.sh脚本\n\u003e - --spring.config.location：指定配置文件目录或者文件名称，如果是目录，以/结束 \n\u003e - \u0026gt; /opt/spring-boot-assembly/logs/spring-boot-assembly.log：指定日志输出路径\n\u003e - 2\u003e\u00261 \u0026 ：将正常的运行日志和错误日志合并输入到指定日志，并在后台运行\n\n#### shutdown.sh停服脚本，实现方式：找到当前项目的PID，然后kill -9\n\n```bash\nPID=$(ps -ef | grep \"${APPLICATION_JAR}\" | grep -v grep | awk '{ print $2 }')\nkill -9 ${PID}\n```\n\n#### 日志记录\n##### 项目启动日志存储路径，一个项目只有一个启动日志文件\n\n```bash\nlogs/startup.log\n```\n\n```text\n================================================ 2018-12-12 12:36:56 ================================================\napplication name: spring-boot-assembly\napplication jar name: spring-boot-assembly.jar\napplication bin path: /opt/spring-boot-assembly/bin\napplication root path: /opt/spring-boot-assembly\napplication log path: /opt/spring-boot-assembly/logs/spring-boot-assembly.log\napplication JAVA_OPT : -server -Xms256m -Xmx256m -Xmn512m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=256m -XX:-OmitStackTraceInFastThrow\napplication background startup command: nohup java -server -Xms256m -Xmx256m -Xmn512m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=256m -XX:-OmitStackTraceInFastThrow -jar /opt/spring-boot-assembly/boot/spring-boot-assembly.jar --spring.config.location=/opt/spring-boot-assembly/config/ \u003e /opt/spring-boot-assembly/logs/spring-boot-assembly.log 2\u003e\u00261 \u0026\napplication pid: 11596\n```\n\n##### 项目运行日志存储路径，最近一次启动项目的运行日志\n\n```bash\nlogs/spring-boot-assembly.log\n```\n\n```text\n.   ____          _            __ _ _\n /\\\\ / ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\\n( ( )\\___ | '_ | '_| | '_ \\/ _` | \\ \\ \\ \\\n \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )\n  '  |____| .__|_| |_|_| |_\\__, | / / / /\n =========|_|==============|___/=/_/_/_/\n :: Spring Boot ::        (v2.1.0.RELEASE)\n\n2018-12-12 23:28:58.420  INFO 11596 --- [           main] o.s.boot.SpringApplication               : Starting application on VM_0_17_centos with PID 11596 (started by root in /opt/spring-boot-assembly)\n2018-12-12 23:28:58.442  INFO 11596 --- [           main] o.s.boot.SpringApplication               : The following profiles are active: local\n2018-12-12 23:29:01.355  INFO 11596 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)\n2018-12-12 23:29:01.437  INFO 11596 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]\n2018-12-12 23:29:01.437  INFO 11596 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.12\n2018-12-12 23:29:01.461  INFO 11596 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]\n2018-12-12 23:29:01.646  INFO 11596 --- [           main] o.a.c.c.C.[.[localhost].[/example]       : Initializing Spring embedded WebApplicationContext\n2018-12-12 23:29:01.647  INFO 11596 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3028 ms\n2018-12-12 23:29:01.708  INFO 11596 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]\n2018-12-12 23:29:01.712  INFO 11596 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]\n2018-12-12 23:29:01.712  INFO 11596 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]\n2018-12-12 23:29:01.712  INFO 11596 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'formContentFilter' to: [/*]\n2018-12-12 23:29:01.713  INFO 11596 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]\n2018-12-12 23:29:02.250  INFO 11596 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'\n2018-12-12 23:29:03.179  INFO 11596 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path '/example'\n2018-12-12 23:29:03.182  INFO 11596 --- [           main] o.s.boot.SpringApplication               : Started application in 5.844 seconds (JVM running for 6.547)\nspring.profiles.active = local\ncontextPath = /example\nserver.port = 8080\nhello = Hello Local\nhttp://localhost:8080/example/hello?name=123\n```\n\n\n##### 项目历史运行日志存储路径，每启动一次项目，会将之前的运行日志移动到back目录\n```text\n`-- logs\n    |-- back\n    |   |-- spring-boot-assembly_back_2018-12-12-23-30-10.log\n    |   `-- spring-boot-assembly_back_2018-12-12-23-36-56.log\n    |-- spring-boot-assembly.log\n    `-- startup.log\n```\n    \n#### maven项目打包\n##### 1. 使用IDEA工具打包,选择对应的profiles,然后clean package\n![mvn-clean-package-local](https://raw.githubusercontent.com/geekidea/spring-boot-assembly/master/img/mvn-clean-package-local.png)\n![mvn-clean-package-dev](https://raw.githubusercontent.com/geekidea/spring-boot-assembly/master/img/mvn-clean-package-dev.png)\n\n##### 2. 使用maven命令打包\n\n```bash\nmvn clean package -Pdev\n```\n##### 3. 使用mvn-package脚本打包\n\u003e window\n\n```bash\nmvn-package.bat dev\n```\n\n\u003e linux/mac\n\n```bash\nsh mvn-package.sh dev\n```\n\n#### FAQ\n##### Q: 项目打成tar包后，不能正常读取resource目录下的某些配置文件\n\n##### A:如果resource目录中还用到其它配置文件，需要在pom.xml和assembly.xml文件的resource中进行配置\n1. pom.xml中的resource默认配置\n\u003e 把需要打包的文件添加到include中\n\n```xml\n\u003c!-- 资源文件配置 --\u003e\n\u003cresource\u003e\n    \u003cdirectory\u003esrc/main/resources\u003c/directory\u003e\n    \u003cfiltering\u003etrue\u003c/filtering\u003e\n    \u003cincludes\u003e\n        \u003cinclude\u003eapplication.yml\u003c/include\u003e\n        \u003cinclude\u003eapplication-${profileActive}.yml\u003c/include\u003e\n        \u003cinclude\u003emapper/**/*.xml\u003c/include\u003e\n        \u003cinclude\u003estatic/**\u003c/include\u003e\n        \u003cinclude\u003etemplates/**\u003c/include\u003e\n        \u003cinclude\u003e*.xml\u003c/include\u003e\n        \u003cinclude\u003e*.properties\u003c/include\u003e\n        \u003c!-- xxx.keystore --\u003e\n        \u003cinclude\u003exxx.keystore\u003c/include\u003e\n    \u003c/includes\u003e\n\u003c/resource\u003e\n```\n\n2. assembly.xml中的resource默认配置\n\u003e 把需要打包的文件添加到include中\n\n```xml\n\u003c!-- 指定输出target/classes中的配置文件到config目录中 --\u003e\n\u003cfileSet\u003e\n    \u003cdirectory\u003e${basedir}/target/classes\u003c/directory\u003e\n    \u003coutputDirectory\u003econfig\u003c/outputDirectory\u003e\n    \u003cfileMode\u003e0644\u003c/fileMode\u003e\n    \u003cincludes\u003e\n        \u003cinclude\u003eapplication.yml\u003c/include\u003e\n        \u003cinclude\u003eapplication-${profileActive}.yml\u003c/include\u003e\n        \u003cinclude\u003emapper/**/*.xml\u003c/include\u003e\n        \u003cinclude\u003estatic/**\u003c/include\u003e\n        \u003cinclude\u003etemplates/**\u003c/include\u003e\n        \u003cinclude\u003e*.xml\u003c/include\u003e\n        \u003cinclude\u003e*.properties\u003c/include\u003e\n        \u003c!-- xxx.keystore --\u003e\n        \u003cinclude\u003exxx.keystore\u003c/include\u003e\n    \u003c/includes\u003e\n\u003c/fileSet\u003e\n```\n    \n##### 参考：\n- https://docs.spring.io/spring-boot/docs/current/maven-plugin/\n- http://maven.apache.org/components/plugins/maven-assembly-plugin/usage.html\n- http://maven.apache.org/plugins/maven-jar-plugin/\n- http://maven.apache.org/components/plugins/maven-dependency-plugin/\n- https://maven.apache.org/plugins/maven-resources-plugin/\n- http://maven.apache.org/guides/introduction/introduction-to-profiles.html","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeekidea%2Fspring-boot-assembly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeekidea%2Fspring-boot-assembly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeekidea%2Fspring-boot-assembly/lists"}