Cannot import the ArrayUtils library. When importing an error occurs error: package org.apache.commons.lang3 does not exist . I import using

 import org.apache.commons.lang3.ArrayUtils; 

On the website with the apache.org documentation at the beginning the name of the library and something like the address to it are written:

org.apache.commons.lang3

Class ArrayUtils

java.lang.Object

extended by org.apache.commons.lang3.ArrayUtils

Which of these should help connect and use the library in my code?

  • you first need to add a library file to the project, how it depends on the environment and the type of project - Komdosh
  • Well, for example, the Arrays library can be simply imported. How to understand when the library is third-party, and when can it be simply connected? - fedotsoldier
  • @FedotSoldier if the package starts with java. or javax. it means it is included in the standard library. If not, it is not included, with rare exceptions. - Sergey Gornostaev 5:43 pm
  • if an error occurs, then the third - party library means - michael_best 5:43 pm
  • And if, third-party, then all the same it is impossible in more detail how to connect it? When taking into account that I have one file with code - fedotsoldier

1 answer 1

And if, third-party, then all the same it is impossible in more detail how to connect it?

Download the jar-file to any convenient place and pass the path to it in the -cp key of the compiler:

 javac -cp /path/to/commons-lang3-3.8.1.jar MyClass.java 

I would like it not for the environment to do everything for you, but it was clear what was happening

Read about CLASSPATH, class loaders and packages. It is best to read from the textbook.

  • And if you set the path to the library in CLASSPATH, will import work? - fedotsoldier
  • Do you mean the CLASSPATH environment variable? - Sergey Gornostaev
  • Well yes. Which is in environment variables. And what else CLASSPATH is? - fedotsoldier
  • CLASSPATH is the place where the compiler and virtual machine are looking for classes. The environment variable of the same name is only one of the ways to set it. By the way, this is not recommended. It is better to use the -cp command line -cp . - Sergey Gornostaev
  • Thank. And what is connected with the “non-recommendability” of this method - fedotsoldier