概述
每一个应用都会引入很多依赖jar包,而且其中大多数都是相同的,这样会导致部署时会花费很长的时间。瘦身部署指的是将第三方jar包依赖剔除,只保留业务接口依赖jar包进行打包部署。
剔除第三方依赖jar包
<project> ... <build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> <configuration> <!-- Exclude JCL and LOG4J since all logging should go through SLF4J. Note that we‘re excluding log4j-<version>.jar but keeping log4j-over-slf4j-<version>.jar --> <packagingExcludes> WEB-INF/lib/commons-logging-*.jar, %regex[^WEB-INF/lib/bussiness-(?!webapp-1|webapp-2).*.jar] </packagingExcludes> </configuration> </plugin> </plugins> </build> ... </project>
Tomcat共享类加载器
【1】catalina.properties 文件
# List of comma-separated paths defining the contents of the "shared" # classloader. Prefixes should be used to define what is the repository type. # Path may be relative to the CATALINA_BASE path or absolute. If left as blank, # the "common" loader will be used as Catalina‘s "shared" loader. # Examples: # "foo": Add this folder as a class repository # "foo/*.jar": Add all the JARs of the specified folder as class # repositories # "foo/bar.jar": Add bar.jar as a class repository # Please note that for single jars, e.g. bar.jar, you need the URL form # starting with file:. # # Note: Values may be enclosed in double quotes ("...") in case either the # ${catalina.base} path or the ${catalina.home} path contains a comma. # Because double quotes are used for quoting, the double quote character # may not appear in a path. shared.loader="${catalina.base}/shared","${catalina.base}/shared/*.jar","${catalina.home}/shared","${catalina.home}/shared/*.jar"
【2】创建 shared 目录将第三方jar包放到这里
参考
http://maven.apache.org/plugins/maven-war-plugin/examples/including-excluding-files-from-war.html
原文地址:https://www.cnblogs.com/BINGJJFLY/p/10481649.html
时间: 2024-11-03 23:52:13