0

I am using Amazon Coretto, a JDK, to write and run Java code. I am trying to use a class from Apache Commons Lang with simple import statements like:

import org.apache.commons.lang3.*

However, everything I have looked up online will only describe how to do this with an IDE like Eclipse. How do I download the org.apache.commons.lang3 class and use its subclasses with only a JDK?

1 Answer 1

3

The best way to do this is to install Maven, create a pom.xml file and add commons-lang as a dependency.

The minimal way is to download from https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.11/commons-lang3-3.11.jar and add the jar to your class path when you compile: javac -cp commons-lang3-3.11.jar Foo.java and when you run: java -cp commons-lang3-3.11.jar:. Foo

The files you see in your working directory should be Foo.java and commons-lang3-3.11.jar. After you have runjavac you will also see Foo.class.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. I tried the second option, and it gave me this error: error: package org.apache.commons.lang3 does not exist. How do I fix this?
You probably don't have the jar where you are telling javac that it is.
Thank you. Just a head up. There is a typo in the statement running java. Colon to Semicolon. java -cp commons-lang3-3.11.jar;. Foo
That depends on the platform : on Linux and OS X, ; on Windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.