在Java中使用和导入外部库/框架 [英] Working with and importing external libraries / frameworks in Java

查看:644
本文介绍了在Java中使用和导入外部库/框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这是一个非常n00b的问题。但作为一名初级开发人员,我从未需要导入和使用其他Java框架。标准库总是足以让我编写我需要编写的类。

Firstly this is a very n00b question. But being a junior dev I've never needed to import and work with other Java Frameworks. The standard library was always good enough for me to write the classes I needed to write.

但现在接触到更多高级概念,我需要开始使用外部框架,例如JSON for Java,Apache的HttpClient for java等。我正在寻找一个基本的理解如何工作以及如何导入这些库,以便您可以开始使用类...

But now getting exposed to more "advanced" concepts, I need to start working with external frameworks, e.g. JSON for Java, Apache's HttpClient for java and so on. And I'm looking for a basic understanding on how this works and how to go about importing these libraries so you can start working with the classes...

所以我的初始理解是这些fraemworks中的每一个都将为您提供包含框架所有类的.jar文件。然后将其导入到您的项目中,并且看到您只需导入它就可以使用项目中的类/库,例如'import org.json。*;'

So my initial understanding is that each of these fraemworks will provide you with a .jar file that contains all the classes for the framework. Which you then import into your project and lo and behold you'll be able to use the classes/library in your project by just importing it e.g. 'import org.json.*;'

理解是否正确?

推荐答案

正确。

您只需将库添加到类路径中,现在就可以使用这些库中的类。
如何将libs添加到类路径取决于您的实际开发环境。例如,如果您使用 Apache Maven ,则只需在项目中定义依赖项(libs) pom.xml 并且Maven会自动为您下载它们。

You just add the libraries to your classpath and are now able to use classes from these libs. How you add the libs to your classpath depends on your actual development environment. If you use Apache Maven for example, you just have to define the dependencies (libs) in your projects pom.xml and Maven downloads them automatically for you.

hth,

- martin

hth,
- martin

这篇关于在Java中使用和导入外部库/框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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