且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用或不使用 Maven 导入 o​​rg.apache Java 依赖项

更新时间:2022-12-12 19:45:34

除非您使用 Maven 结构(请参阅此处 Maven 入门)您必须手动下载所有 jar.

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.

要开始在 Netbeans 中使用 Maven,您可以访问:新项目,类别:Maven 项目:{Best Option}.然后在项目文件中,打开 pom.xml.这是添加项目依赖项的位置.如果您不确定要插入什么,请尝试在 Internet 上搜索您的 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>