How to use Apache Commons Lang code without an IDE? (org.apache.commons.lang3)

1k views Asked by At

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

There are 1 answers

4
tgdavies On

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.