如何使用 org.apache.commons 包? [英] How to use org.apache.commons package?

查看:145
本文介绍了如何使用 org.apache.commons 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在各种网络示例中,我看到了如下导入:

On various web examples I see imports such as:

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

我不明白如何使用这些,而且 apache 网站也相当不清楚.如何使用这些类?我希望我需要下载一些东西,但如果能提供一些指导,我们将不胜感激.

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.

推荐答案

您应该下载包含这些库的 jar 文件.可以通过将库添加到类路径来使用库.

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

对于 Commons Net,您需要从 Commons Net 下载页面下载二进制文件.然后,您必须提取该文件并将 commons-net-2-2.jar 文件添加到您可以从应用程序访问它的某个位置,例如到/lib.

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.

如果您从命令行运行应用程序,则必须在 java 命令中定义类路径:java -cp .;lib/commons-net-2-2.jar myapp.有关如何设置类路径的更多信息可以可以从 Oracle 文档中找到.您必须在类路径中指定您需要的所有目录和 jar 文件,不包括那些由 Java 运行时隐式提供的目录和 jar 文件.请注意,有."在类路径中,它用于包含当前目录,以防您编译的类位于当前目录中.

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.

要获得更高级的阅读,您可能需要阅读 如何为您自己的 jar 文件定义类路径,或 war 文件的目录结构,当您创建 Web 应用程序时.

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.

如果您使用的是 IDE,例如 Eclipse,您必须记住在 IDE 识别它并允许您使用该库之前将该库添加到您的构建路径中.

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.

这篇关于如何使用 org.apache.commons 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆