工作中我们会遇到这样的一种场景,就是写好的代码封包给别的部门使用或者项目使用,如果我们此时按照正常的打包流程的话,对方是可以使用maven引入包的,但是包内的类缺无法引入使用,此时就需要我们下面所说的这种方式来解决
完整代码可参考GitHub
https://github.com/zuiyu-main...
问题
maven可以引入,却不能 import 类使用
解决
-
首先还是新建一个模块测试,license-common,修改
pom.xml
中的打包插件为下面这种<groupId>com.zuiyu</groupId> <artifactId>license-common</artifactId> <version>0.0.1-SNAPSHOT</version> <name>license-common</name> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>
- 执行idea中的打包,也就是
mvn install
-
需要该模块代码的项目pom中加入
<dependency> <groupId>com.zuiyu</groupId> <artifactId>license-common</artifactId> <version>0.0.1-SNAPSHOT</version> <scope>compile</scope> </dependency>
总结
完整的核心pom文件如下,只保留打包相关
-
license-common
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.zuiyu</groupId> <artifactId>license-common</artifactId> <version>0.0.1-SNAPSHOT</version> <name>license-common</name> <description>license-client</description> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>
-
License-client
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.zuiyu</groupId> <artifactId>client</artifactId> <version>0.0.1-SNAPSHOT</version> <name>license-client</name> <description>license-client</description> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring-boot.version>2.1.18.RELEASE</spring-boot.version> </properties> <dependencies> <dependency> <groupId>com.zuiyu</groupId> <artifactId>license-common</artifactId> <version>0.0.1-SNAPSHOT</version> <scope>compile</scope> </dependency> </dependencies> </project>
本文由mdnice多平台发布
相关文章
暂无评论...