import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class ListTables {
public static void main(String args[])throws MasterNotRunningException, IOException {
ConnectionFactory.createConnection();
System.out.println("stage 1. . . . ");
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "192.168.*.***");
conf.set("hbase.master", "192.168.*.***:60000");
conf.set("hbase.zookeeper.property.clientPort","2181");
conf.set("zookeeper.znode.parent","/hbase-unsecure");
Connection connection = ConnectionFactory.createConnection(conf);
try {
HBaseAdmin admin1 = (HBaseAdmin)connection.getAdmin();
System.out.println("stage 3. . . . ");
HTableDescriptor tableDescriptor[] = admin1.listTables();
for (int i=0; i<tableDescriptor.length; i++) {
System.out.println(tableDescriptor[i].getNameAsString());
}
} catch (Exception e) {
System.out.println(e);
}
}
}
输出
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
stage 1. . . .
stage 3. . . .
这是错误
在这一行之后,我等待了很长时间,但没有回应。
答案 0 :(得分:0)
我遇到了同样的错误,我不得不创建log4j.properties,这是因为Hadoop使用log4j来编写日志:
项目Java:resources / log4j.properties
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\path of your `enter code here`file\\pruebas\\log\\log.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
我希望这会对你有所帮助。