简体   繁体   English

如何使用org.apache.commons包?

[英]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. 我不明白如何使用这些,而apache网站还不太清楚。 How to I use these classes? 我如何使用这些类? I'm expecting I need to download something, but a little direction would be greatly appreciated. 我期待我需要下载一些东西,但是我会非常感谢一点方向。

You are supposed to download the jar files that contain these libraries. 您应该下载包含这些库的jar文件。 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 . 对于Commons Net,您需要从Commons Net下载页面下载二进制文件。 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 eg to /lib. 然后你必须解压缩文件并将commons-net-2-2.jar文件添加到某个位置,你可以从你的应用程序访问它,例如/ 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 . 如果从命令行运行应用程序,则必须在java命令中定义类路径: java -cp .;lib/commons-net-2-2.jar myapp More info about how to set the classpath can be found from Oracle documentation. 有关如何设置类路径的更多信息可以从Oracle文档中找到。 You must specify all directories and jar files you'll need in the classpath excluding those implicitely provided by the Java runtime. 您必须在类路径中指定所需的所有目录和jar文件,不包括Java运行时隐式提供的那些目录和jar文件。 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. 有关更高级的读取,您可能希望了解如何在创建Web应用程序时为自己的jar文件定义类路径 ,或者为war文件的目录结构

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. 如果您使用的是IDE(例如Eclipse),则必须记住在IDE识别它之前将库添加到构建路径并允许您使用该库。

Download commons-net binary from here . 这里下载commons-net二进制文件。 Extract the files and reference the commons-net-xxjar file. 提取文件并引用commons-net-xxjar文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM