如何导入 org.apache Java 依赖项 w/或 w/o Maven
所以快速背景是我正在创建一个 java 程序,它使用许多不同的导入
So the quick background is I am creating a java program, that uses many different imports
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.util.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
我知道 Netbeans 没有找到这些文件,因为我的计算机上没有这些文件.但是有没有办法让 Netbeans 自动连接 org.apache 并检索这些文件?还是我只需要去下载它们.有人推荐使用 Maven,但我不确定这是否是正确的解决方案或如何解决?
I know that Netbeans isn't finding these files because I do not have them on my computer. But is there a way to have Netbeans automatically connect with org.apache and retrieve these files? Or do I just have to go and download them. Someone recommended using Maven, but I am not sure if this is the right solution or how to go about that?
谢谢
推荐答案
除非你使用 Maven 结构(见这里 开始使用 Maven) 你必须手动下载所有的 jars.
Unless you use a Maven structure (see here getting started with Maven) you will have to download all jars manually.
如果仅使用 Hadoop(如您的示例),这似乎没什么大不了的,但是在处理大型项目时,在 pom.xml 文件中声明您的依赖项会更容易.它比下载 X 个不同的 jar 更容易,而且您可以轻松地迁移到更新版本的库,而不必删除并下载另一个.
If using only Hadoop (as in your example) this might not seem that much of a deal, but when working with big projects it is easier to declare your dependencies in a pom.xml file. It is much more easier than downloading X different jars, and you can easily move to a newer version of a library, rather than having to delete and and download another.
我看到有人在评论中问为什么人们如此喜欢 Maven.好吧,老实说,我个人觉得它易于使用且非常有用.此外,一个 Maven 项目可以很容易地导入 IntelliJ、Eclipse 或 Netbeans,而创建一个 IntelliJ 项目可能会导致在 Eclipse 或 NetBeans 中导入它的困难.
I saw that someone asked in a comment why people like Maven so much. Well, to be honest, I personally find it easy to use and very useful. Furthermore, a Maven project can be easily imported in IntelliJ, Eclipse or Netbeans, whereas creating for example an IntelliJ project can cause difficulties in importing it in Eclipse or NetBeans.
要开始将 Maven 与 Netbeans 一起使用,您可以转到:新项目、类别:Maven 项目:{最佳选项}.然后在项目文件中,打开 pom.xml.这里是为您的项目添加依赖项的地方.如果您不确定要插入什么,请尝试在互联网上搜索您的 jar 名称 +maven".Netbeans 插件能够连接到 maven 存储库并自动完成大多数字段.
To get started using Maven with Netbeans, you can go to: New Project, Categories:Maven Projects:{Best Option}. Then in the project files, open pom.xml. Here is where dependencies for your project are added. If you are not sure what to insert try searching for your jar name + "maven" on the internet. The plugin for Netbeans is able to connect to the maven repository and autocomplete most fields.
示例来自:http://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.6
<project...>
....
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
...
</project>
相关文章