无法解析符号 hbase
Cannot resolve symbol hbase
我是HBase的新手,我从网上复制了一个示例代码java,但是我遇到了一个错误"Cannot resolve symbol hbase" 构建此示例时。我使用 Gradle 构建此示例项目,使用 Intellij 作为 IDE。 HBase 服务器是一个远程服务器,我尝试在我的 windows 笔记本电脑上编写一个 put 示例来测试 HBase,但我不熟悉 HBase 和 Gradle,有人可以建议我错过了什么吗?这是我的代码
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
public class PutHbaseClient {
public static void main(String[] args) throws IOException {
Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf("test"));
try {
/*
* Put operations for a single row. To perform a
* Put, instantiate a Put object with the row to insert to and for
* each column to be inserted, execute addcolumn.
*/
Put put1 = new Put(Bytes.toBytes("row1"));
Put put2 = new Put(Bytes.toBytes("row2"));
Put put3 = new Put(Bytes.toBytes("row3"));
put1.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"),
Bytes.toBytes("ValueOneForPut1Qual1"));
put2.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"),
Bytes.toBytes("ValueOneForPut2Qual1"));
put3.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"),
Bytes.toBytes("ValueOneForPut2Qual1"));
put1.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual2"),
Bytes.toBytes("ValueOneForPut1Qual2"));
put2.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual2"),
Bytes.toBytes("ValueOneForPut2Qual2"));
put3.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual2"),
Bytes.toBytes("ValueOneForPut3Qual3"));
table.put(put1);
table.put(put2);
table.put(put3);
} finally {
table.close();
connection.close();
}
}
}
这是我的 build.gradle
plugins {
id 'java'
}
group 'gid'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.apache.hadoop', name: 'hadoop-common', version:'2.7.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
我认为您的 gradle 依赖项中需要这样的东西:
compile 'org.apache.hbase:hbase:3.0.0-SNAPSHOT'
根据 JAR 查找器站点,org.apache.hadoop.hbase.TableName
class 在 hbase-common JAR 文件中。
这意味着您在 build.gradle 文件中的依赖项 应该 有效。但是,我认为版本号不正确。 Maven Central 中最新的 2.x 版本是 2.2.2。 (并且 3.0.0-SNAPSHOT 不存在......自然......因为 Maven Central 不托管 SNAPSHOT 工件!)
但是,我建议您按照 HBase 文档中的说明进行操作 (here):
"For Java applications using Maven, including the hbase-shaded-client
module is the recommended dependency when connecting to a cluster."
对应的Gradle依赖为:
// https://mvnrepository.com/artifact/org.apache.hbase/hbase-shaded-client
compile group: 'org.apache.hbase', name: 'hbase-shaded-client', version: '2.2.2'
我不熟悉 Gradle,但我预计会有另一条错误消息说它无法解析 hbase-common 版本 2.7.3 的依赖关系。
我是HBase的新手,我从网上复制了一个示例代码java,但是我遇到了一个错误"Cannot resolve symbol hbase" 构建此示例时。我使用 Gradle 构建此示例项目,使用 Intellij 作为 IDE。 HBase 服务器是一个远程服务器,我尝试在我的 windows 笔记本电脑上编写一个 put 示例来测试 HBase,但我不熟悉 HBase 和 Gradle,有人可以建议我错过了什么吗?这是我的代码
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
public class PutHbaseClient {
public static void main(String[] args) throws IOException {
Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf("test"));
try {
/*
* Put operations for a single row. To perform a
* Put, instantiate a Put object with the row to insert to and for
* each column to be inserted, execute addcolumn.
*/
Put put1 = new Put(Bytes.toBytes("row1"));
Put put2 = new Put(Bytes.toBytes("row2"));
Put put3 = new Put(Bytes.toBytes("row3"));
put1.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"),
Bytes.toBytes("ValueOneForPut1Qual1"));
put2.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"),
Bytes.toBytes("ValueOneForPut2Qual1"));
put3.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"),
Bytes.toBytes("ValueOneForPut2Qual1"));
put1.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual2"),
Bytes.toBytes("ValueOneForPut1Qual2"));
put2.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual2"),
Bytes.toBytes("ValueOneForPut2Qual2"));
put3.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual2"),
Bytes.toBytes("ValueOneForPut3Qual3"));
table.put(put1);
table.put(put2);
table.put(put3);
} finally {
table.close();
connection.close();
}
}
}
这是我的 build.gradle
plugins {
id 'java'
}
group 'gid'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.apache.hadoop', name: 'hadoop-common', version:'2.7.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
我认为您的 gradle 依赖项中需要这样的东西:
compile 'org.apache.hbase:hbase:3.0.0-SNAPSHOT'
根据 JAR 查找器站点,org.apache.hadoop.hbase.TableName
class 在 hbase-common JAR 文件中。
这意味着您在 build.gradle 文件中的依赖项 应该 有效。但是,我认为版本号不正确。 Maven Central 中最新的 2.x 版本是 2.2.2。 (并且 3.0.0-SNAPSHOT 不存在......自然......因为 Maven Central 不托管 SNAPSHOT 工件!)
但是,我建议您按照 HBase 文档中的说明进行操作 (here):
"For Java applications using Maven, including the
hbase-shaded-client
module is the recommended dependency when connecting to a cluster."
对应的Gradle依赖为:
// https://mvnrepository.com/artifact/org.apache.hbase/hbase-shaded-client
compile group: 'org.apache.hbase', name: 'hbase-shaded-client', version: '2.2.2'
我不熟悉 Gradle,但我预计会有另一条错误消息说它无法解析 hbase-common 版本 2.7.3 的依赖关系。