1、在瘦身之前先打出一个完整的jar包,解压后将lib全部拿出来,删除非第三方的jar (删除自己项目中的依赖包)
2、获取 功能 的maven 依赖GroupIds (红色为需要保留在jar包中的groupId字符串)
mvn dependency:tree|grep -e "compile" -e "runtime"|sed 's/|//g'|sed 's/+//g'|awk '{print $3}'|awk -F ":" '{print $1,","}'|sort|uniq|grep -vE "(com.****|common-)"|xargs
3、在maven配置文件中添加
4、重新打包出一个thin jar ,运行 java -Dloader.path=lib/ -jar demo.jar
org.springframework.boot
spring-boot-maven-plugin
true
ZIP
aopalliance,ch.qos.logback,com.alibaba,com.amazonaws,com.fasterxml,
com.fasterxml.jackson.core,com.fasterxml.jackson.dataformat,com.fasterxml.jackson.module,
com.fasterxml.woodstox,com.github.jsqlparser,com.github.pagehelper,
com.google.code.findbugs,com.googlecode.javaewah,com.google.guava,com.google.inject,
com.jcraft,commons-beanutils,commons-codec,commons-collections,commons-configuration,
commons-lang,commons-logging,com.netflix.archaius,com.netflix.eureka,com.netflix.feign,
com.netflix.governator,com.netflix.hystrix,com.netflix.netflix-commons,com.netflix.ribbon,
com.netflix.servo,com.sun.jersey,com.sun.jersey.contribs,com.thoughtworks.xstream,com.trilead,
de.regnis.q.sequence,io.netty,io.reactivex,javax.inject,javax.validation,javax.ws.rs,
javax.xml.stream,net.java.dev.jna,net.sf.ehcache,org.antlr,org.apache.commons,
org.apache.httpcomponents,org.apache.shiro,org.apache.tomcat.embed,org.aspectj,org.bouncycastle,
org.codehaus.jettison,org.codehaus.woodstox,org.eclipse.jgit,org.freemarker,org.hdrhistogram,
org.hibernate,org.jasig.cas.client,org.jboss.logging,org.jvnet,org.opensymphony.quartz,org.ow2.asm,
org.slf4j,org.springframework,org.springframework.boot,org.springframework.cloud,
org.springframework.security,org.tmatesoft.sqljet,org.tmatesoft.svnkit,org.yaml,stax,xmlpull,xpp3
com.cloud.discovery.DiscoveryApplication
repackage