java.lang does not contain a class called StringUtils. Several third-party libs do, such as Apache Commons Lang or the Spring framework. Make sure you have the relevant jar in your project classpath and import the correct class.
java.lang does not contain a class called StringUtils. Several third-party libs do, such as Apache Commons Lang or the Spring framework. Make sure you have the relevant jar in your project classpath and import the correct class.
StringUtils is an Apache Commons project. You need to download and add the library to your classpath.
To use:
import org.apache.commons.lang3.StringUtils;
I have added commons-lang-2.6.jar & commons-lang3-3.1-sources.jar...
Here's your problem: commons-lang-2.6.jar doesn't contain the org.apache.commons.lang3 package, since that's part of version 3, and commons-lang3-3.1-sources.jar contains the source code, not the byte code.
You need to include commons-lang3-3.1.jar instead.
If you're using Maven, put this inside your pom.xml file:
Maven Central Repository for Commons Lang:
Copy<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
Maven Central Repository for Apache Commons Lang:
Copy<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17</version>
</dependency>
Don't forget to Update Maven Project
mvn clean install -U
If you're using Gradle, put this inside your build.gradle file:
Copyimplementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0'
Gradle (Short)
Copyimplementation 'commons-lang:commons-lang:2.6'
implementation 'org.apache.commons:commons-lang3:3.17.0'
Gradle (Kotlin)
Copyimplementation("commons-lang:commons-lang:2.6")
implementation("org.apache.commons:commons-lang3:3.17.0")
Don't forget to Update Gradle Project
gradle --refresh-dependencies clean build
Apache Commons Lang Dependency Information
Last Published: 29 August 2024 | Version: 3.17
Apache Maven
Copy<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>
Apache Ivy
Copy<dependency org="org.apache.commons" name="commons-lang3" rev="3.17.0">
<artifact name="commons-lang3" type="jar" />
</dependency>
Groovy Grape
Copy@Grapes(
@Grab(group='org.apache.commons', module='commons-lang3', version='3.17.0')
)
Gradle/Grails
Copyimplementation 'org.apache.commons:commons-lang3:3.17.0'
Scala SBT
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.17.0"
Leiningen
Copy[org.apache.commons/commons-lang3 "3.17.0"]
Reference:
- https://commons.apache.org/proper/commons-lang/index.html
- https://commons.apache.org/proper/commons-lang/dependency-info.html
Maven Central Repository Artifacts:
- https://mvnrepository.com/artifact/commons-lang/commons-lang
- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
The class was moved from package
org.apache.commons.
lang3
to
org.apache.commons.text
You can replace the deprecated library easily:
In your build.gradle:
implementation 'org.apache.commons:commons-text:1.11.0'
And in your class using StringEscapeUtils make sure you import the correct class:
import org.apache.commons.text.StringEscapeUtils;
1.11.0 is currently the newest version (last checked February 20th 2024) but you can check the versions at maven: https://mvnrepository.com/artifact/org.apache.commons/commons-text
Per the deprecation listing, it was moved to a new project -- commons-text
Seriously, what madness drove the commons lang contributors to deprecate StringUtils.equals()?
I'm gonna rant for a bit here. It's been a long day.
I spend all morning in an incident call, finally get time to do some coding in the afternoon.
I make progress on a bug fix, clean up some dead code like a good boy scout, and I’m feeling like I actually accomplished something today.
Oh, this service is getting flagged for CVE-2025-48924? Let me take care of that.
And then, confusion. Anger.
Deprecated method? StringUtils.equals()? That can't be.
Sure as shit, they deprecated it. Let's see what has been replaced with.
Strings.CS.equals()? Is that character sequence? No, it's case sensitive. Fucking hell. I harp on juniors for their silly acronyms. Did not expect to see them in a library like this. Just unnecessary. If Java developers had a problem with verbosity, well, they wouldn't be Java developers.
I'll admit I've been an open-source leech, contributing nothing to the community, but this one has lit a fire in me.
If this issue isn't resolved, are there any volunteers to help with a fork? I feel like common-sense-lang3 would be an appropriate name for an alternative.
https://issues.apache.org/jira/projects/LANG/issues/LANG-1777?filter=allopenissues