我写了一个简单的java代码,它将列出Hbase中的所有表。它在日食上运行良好。但是当我将它转换为runnable jar并尝试运行它时,我得到java.lang.ExceptionInInitializerError
异常。
以下是我的java代码
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.*;
public class ListTables {
public static void main(String[] args) throws IOException {
System.out.println(System.getProperty("java.version"));
System.out.println();
System.out.flush();
Configuration conf= HBaseConfiguration.create();
Connection conn= ConnectionFactory.createConnection(conf);
Admin admin= conn.getAdmin();
HTableDescriptor tableDes[]= admin.listTables();
for(HTableDescriptor td : tableDes) {
System.out.print(td.getNameAsString() + " : ");
for(HColumnDescriptor cd : td.getColumnFamilies())
System.out.print(cd.getNameAsString() + ", ");
System.out.println();
}
}
}
我在将Jar转换为runnable jar后运行Jar时遇到异常
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:78)
at org.apache.hadoop.security.Groups.parseStaticMapping(Groups.java:93)
at org.apache.hadoop.security.Groups.<init>(Groups.java:77)
at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:240)
at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:225)
at org.apache.hadoop.hbase.security.UserProvider.<clinit>(UserProvider.java:56)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:214)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:119)
at ListTables.main(ListTables.java:14)
Caused by: java.lang.StringIndexOutOfBoundsException: begin 0, end 3, length 1
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3116)
at java.base/java.lang.String.substring(String.java:1885)
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:49)
... 9 more
任何人都可以告诉我们将这些类型的代码转换为可运行的Jar的正确方法是什么......
答案 0 :(得分:0)
挖掘源代码,您可以发现Shell类中的这种情况失败
private static boolean IS_JAVA7_OR_ABOVE =
System.getProperty("java.version").substring(0, 3).compareTo("1.7") >= 0;
检查您的java.version
系统属性,也可以在代码中设置