开发避坑指南(67):Maven引入iText7-core依赖失败解决方案
异常信息
<dependency><groupId>com.itextpdf</groupId><artifactId>itext7-core</artifactId><version>${itextpdf.version}</version>
</dependency>
在maven中引入itext7-core的上述坐标编译时报错找不到itext-core:
com.itextpdf:itext-core:jar:9.3.0 was not found in https://maven.aliyun.com/repository/public during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of public has elapsed or updates are forced
异常分析
itext7-core 采用了高度模块化的设计,核心功能与扩展功能分离,开发者可按需引入模块。相比之下,itextpdf (通常指 iText 5) 是一个功能集中的单一 JAR 包。
所以在引入itext7-core的坐标时,坐标的type标签值需修改为pom,而不指定type标签时,默认是jar。
解决办法
坐标增加<type>pom</type>,如下
<dependency><groupId>com.itextpdf</groupId><artifactId>itext7-core</artifactId><version>${itextpdf.version}</version><type>pom</type>
</dependency>
