Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use org.apache.commons package?

On various web examples I see imports such as:

import org.apache.commons.net.ftp.FTPClient; 

I don't understand how to use these, and the apache website is fairly unclear. How to I use these classes? I'm expecting I need to download something, but a little direction would be greatly appreciated.

like image 247
Connor Avatar asked Feb 27 '11 02:02

Connor


People also ask

What is the use of Org Apache Commons?

The Apache Commons is a project of the Apache Software Foundation, formerly under the Jakarta Project. The purpose of the Commons is to provide reusable, open source Java software. The Commons is composed of three parts: proper, sandbox, and dormant.

What is the use of Commons lang3?

lang3. Provides highly reusable static utility methods, chiefly concerned with adding value to the java. lang classes.


2 Answers

You are supposed to download the jar files that contain these libraries. Libraries may be used by adding them to the classpath.

For Commons Net you need to download the binary files from Commons Net download page. Then you have to extract the file and add the commons-net-2-2.jar file to some location where you can access it from your application e.g. to /lib.

If you're running your application from the command-line you'll have to define the classpath in the java command: java -cp .;lib/commons-net-2-2.jar myapp. More info about how to set the classpath can be found from Oracle documentation. You must specify all directories and jar files you'll need in the classpath excluding those implicitely provided by the Java runtime. Notice that there is '.' in the classpath, it is used to include the current directory in case your compiled class is located in the current directory.

For more advanced reading, you might want to read about how to define the classpath for your own jar files, or the directory structure of a war file when you're creating a web application.

If you are using an IDE, such as Eclipse, you have to remember to add the library to your build path before the IDE will recognize it and allow you to use the library.

like image 195
Aleksi Yrttiaho Avatar answered Sep 25 '22 16:09

Aleksi Yrttiaho


Download commons-net binary from here. Extract the files and reference the commons-net-x.x.jar file.

like image 32
Bala R Avatar answered Sep 25 '22 16:09

Bala R