How to use org.apache.commons package?

2019-01-11 00:14发布

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.

2条回答
Summer. ? 凉城
2楼-- · 2019-01-11 01:00

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-11 01:00

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

查看更多
登录 后发表回答