简体   繁体   English

Apache lang3有效,但Apache lang无效。 为什么?

[英]Apache lang3 works but Apache lang does not. Why?

I have implemented the spring boot project with starter parent pom version 2.0.3. 我已经使用起始父pom版本2.0.3实现了spring boot项目。 When I try to use 当我尝试使用

import org.apache.commons.lang.StringUtils

it throws error import cannot be resolved. 它会引发错误导入,无法解决。 Even though my m2 folder (C:\\Users\\.m2\\repository\\org\\apache\\commons) have lang package (commons-lang folder)installed. 即使我的m2文件夹(C:\\ Users \\ .m2 \\ repository \\ org \\ apache \\ commons)已安装lang包(commons-lang文件夹)。 I also have commons-lang3 folder. 我也有commons-lang3文件夹。 If I change import to 如果我将导入更改为

import org.apache.commons.lang3.StringUtils

It works fine. 工作正常。

I have same version of starter pom in other spring boot project and there I am able to use commons.lang. 我在其他spring boot项目中具有相同版本的starter pom,并且可以在其中使用commons.lang。 Not able to identify the root cause. 无法确定根本原因。

As far as I can see the spring boot starter parent depends only on commons-lang3 and not on commons-lang (which is reasonable because commons-lang3 is a newer replacement for commons-lang). 据我所知, Spring Boot Starter父级仅依赖于commons-lang3而不依赖commons-lang(这是合理的,因为commons-lang3是commons-lang的较新替代品)。

It doesn't matter that your .m2 directory contains commons-lang (probably due to some other project depending on it): as long as your project hasn't declared a (direct or indirect) dependency on commons-lang, none of its classes will be on your classpath. .m2目录包含commons-lang无关紧要(可能是由于其他项目依赖于它):只要您的项目未声明对commons-lang的(直接或间接)依赖关系,类将在您的类路径上。

Call mvn dependency:tree on your "other" project. 在“其他”项目上调用mvn dependency:tree Here you can see through which path you drew commons-lang. 在这里,您可以看到绘制commons-lang的路径。 Joachim Sauer is probably right and it is a transitive dependency that you started to use like a direct one. Joachim Sauer可能是正确的,它是一种传递依赖,您开始像直接引用一样使用它。

Best fix would be to start to use commons-lang3 for your project (again, Joachim Sauer is right here), second best fix would be to declare commons-lang as a direct dependency in your pom.xml . 最好的解决方法是开始在您的项目中使用commons-lang3(同样,Joachim Sauer就在此处),第二个最好的解决方法是将commons-lang声明为pom.xml的直接依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM