Bobcares

How to Fix “package org.apache.commons.lang does not exist” Error in Java

by | Dec 8, 2024

Learn how to fix the “package org.apache.commons.lang does not exist” Error in Java. Our Apache team is here to help you with your questions and concerns.

How to Fix “package org.apache.commons.lang does not exist” Error in Java

How to Fix “package org.apache.commons.lang does not exist” Error in JavaYou can stop worrying if you have come across the following lines in a Java stack trace!

package org.apache.commons.lang does not exist

static import only from classes and interfaces

Although frustrating, this error is easy to fix once we understand the root causes and solutions.

Our Experts have put together this guide to help you resolve this issue.

An Overview:

Understanding Apache Commons Lang

Apache Commons Lang is a popular Java library that enhances standard Java capabilities with utility functions for string manipulation, object comparisons, concurrency, and more.

The library’s classes and methods are organized under the `org.apache.commons.lang3` package in modern versions (3.x and above). Older versions used `org.apache.commons.lang`. These differences in package names are often the source of confusion.

Common Causes of the Error

  1. The `org.apache.commons.lang` package belongs to the Apache Commons Lang library. If this library is not added to our project dependencies, the Java compiler will throw the “does not exist” error.
  2. Modern versions of the library (3.x and above) use the `org.apache.commons.lang3` package. If our code references `org.apache.commons.lang`, we may be using an outdated version or need to update our imports.
  3. The library might not be correctly configured in the project’s classpath even if the library is downloaded. Without proper configuration, the compiler cannot locate the required classes.

How to Resolve the Error

1. Add the Library Dependency

Using a build tool like Maven or Gradle makes dependency management straightforward.

We need to add the following dependency to our `pom.xml` file for Maven:


<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version> <!-- Replace with the latest version -->
</dependency>

If we are using Gradle, we have to include this in our `build.gradle` file:

implementation 'org.apache.commons:commons-lang3:3.12.0' // Update version as needed

Save the changes and refresh your project. The build tool will automatically fetch and configure the required library in our classpath.

2. Download the JAR Manually (Standalone Projects)

We can manually download the Apache Commons Lang JAR file from this link for standalone projects without build tools.

https://commons.apache.org/proper/commons-lang/

  1. First, download the latest JAR file.
  2. Then, add it to the classpath. For example, compile the Java code with the following command:


    javac -cp "path/to/commons-lang3-3.12.0.jar" YourClass.java

3. Correct the Package Name

Modern versions of Apache Commons Lang (3.x and above) use the package `org.apache.commons.lang3`. If our code references `org.apache.commons.lang`, we have to update our imports:


// Replace this
import org.apache.commons.lang.StringUtils;
// With this
import org.apache.commons.lang3.StringUtils;

This change ensures compatibility with the current library version.

4. Verify IDE Configuration

If we are using an Integrated Development Environment (IDE) like IntelliJ IDEA or Eclipse, ensure that:

  • The library is added to the build path or dependencies section.
  • Then, the project is refreshed to reflect changes in dependencies.
  • Rebuild the project to ensure the compiler includes the library.

In IntelliJ IDEA:

  • Go to File > Project Structure > Libraries and ensure the library is added.
  • Then, click `Reload All Maven Projects` if using Maven.

In Eclipse, right-click the project, go to `Build Path > Configure Build Path,` and add the library under the `Libraries` tab.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

The “package org.apache.commons.lang does not exist” error is a common issue caused by missing libraries, incorrect versions, or misconfigured classpaths. We can quickly resolve the issue by adding the Apache Commons Lang library through a build tool, updating package names, or fixing classpath configurations.

In brief, our Support Experts demonstrated how to fix the “package org.apache.commons.lang does not exist” Error in Java.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF