1.场景
一个系统使用了多套或多个版本的jar或系统,jar包用不能同时存在于本系统中。
2.处理阶段
代码完成编译执行依赖拷贝时通过一定的策略来阻止一些不必要的jar包拷贝
3.操作过程
配置pom中相关以来的scope
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.67</version> <scope>${cdh}</scope> </dependency> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>2.6.0</version> <scope>${hw}</scope> </dependency>
第二配置 plugins
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib/</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> <includeScope>compile</includeScope> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> </plugins> </build>
第三配置profies来完成通过参数实现动态加载
<profiles> <profile> <id>hw</id> <properties> <cdh>test</cdh> <hw>compile</hw> </properties> </profile> <profile> <id>cdh</id> <properties> <hw>provided</hw> <cdh>compile</cdh> </properties> </profile> </profiles>
最后通过mvn install -P hw来完成动态加载