如何使用 Maven 自动下载程序所需的依赖项?

发布于 2024-12-01 23:49:36 字数 625 浏览 4 评论 0原文

我刚开始使用 Maven。

我有具有依赖关系的 Java 文件。 例如:

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;

在开发服务器中,没有Java编译器。我打算在桌面上编译Java文件并将类打包成jar文件,然后在开发服务器上执行程序。

开发服务器拥有所有必需的文件,但桌面还没有。我们如何使用Maven来处理在桌面上编译的问题?

编辑:

我想使用 Java 将数据添加到 hbase 表中。 Hbase 在开发服务器中运行良好。我可以通过开发服务中的命令行在那里创建表。但桌面环境中不存在hbase/hadoop。

那么下载 jar 有帮助吗,还是我需要在本地设置 hadoop 并安装 hbase ?

I am new to using Maven.

I have Java files that have dependencies.
Like for example:

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;

In the development server, there is no Java compiler. I am planning to compile the Java files on the desktop and pack the classes into jar files and then execute the program on the development server.

The development server has all the required files, the desktop not yet. How can we use Maven to care of the issue while compiling it on the desktop?

EDIT:

I want to add data into hbase tables using Java. Hbase works fine in the dev server. I am able to create tables there through command line in dev serv. But hbase/hadoop is not there in the desktop environment.

So will downloading jars help, or do I need to setup hadoop and install hbase locally?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

坏尐絯 2024-12-08 23:49:36

如果我理解正确,您需要配置一些 编译时-Maven pom 中的仅依赖项。您可以在dependencies部分中完成此操作,例如:

<dependencies>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>0.20.2</version>
        <scope>provided</scope>
    </dependency>
    ...
</dependencies>

您需要确定每个所需的Hadoop包的artifactId和版本,然后将它们添加到依赖项中。

If I understand correctly, you need to configure some compile-time-only dependencies in your Maven pom. You can do it in the dependencies section, e.g.:

<dependencies>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>0.20.2</version>
        <scope>provided</scope>
    </dependency>
    ...
</dependencies>

You need to determine the artifactId and version for each of the needed Hadoop packages, then add them to the dependencies.

淡淡の花香 2024-12-08 23:49:36

是的,Maven 有一个近乎垂直的学习曲线。

看起来您正在独自或与一个非常小的团队一起做一项非常小的内部工作。
在这种情况下,如果您设置一个 IDE(Eclipse 或 NetBeans)可能就足够了,
手动解决依赖关系(将 jar 下载到项目的 /lib 文件夹中),并手动编译并导出二进制文件 (jar)。

Yes, Maven has a near vertical learning curve.

It looks like you are doing a very small inhouse job on your own, or with a very small team.
In that case, it's probably enough if you set up an IDE (eclipse or NetBeans),
resolving the dependencies manually (downloading jars in a /lib folder in the project), and compile and export a binary (jar) manually.

以可爱出名 2024-12-08 23:49:36

hadoop-core、hbase 和zookeeper 是必需的HBase 依赖项。此外,您应该尝试使用 Cloudera 的,因为它们修复了 Apache jar 存在的一些其他错误。请查看此处

此外,您不必在本地安装 HBase。创建 HBase 配置时,只需更改 Zookeeper quorom 以指向 Zookeeper 所在的服务器。

Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", SERVER);
conf.set("hbase.zookeeper.property.clientPort", PORT);

hadoop-core, hbase, and zookeeper are the required HBase dependencies. Additionally, you should try and use the Cloudera ones as they fix some additional bugs the Apache jars have. Look here.

Additionally, you do not have to install HBase locally. When you create the HBase configuration just change the zookeeper quorom to point to the server in which the Zookeeper resides.

Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", SERVER);
conf.set("hbase.zookeeper.property.clientPort", PORT);
今天小雨转甜 2024-12-08 23:49:36

maven 站点,将 scope 设置为 为依赖项提供

From the maven site, set the scope to provided for the dependency.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文