2015-04-15 83 views
0

我有一個簡單的單元測試,我想對HBaseTestingUtility MiniCluster運行。缺少使用HBaseTestingUtility運行測試所需的傳遞依賴關係。我一直在追查NoClassDefFoundErrors,並且遇到了其中一個jar文件的打包錯誤。這裏的錯誤:HBaseTestingUtility與MiniCluster一起工作嗎?

java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/test/MetricsAssertHelper at org.apache.hadoop.hbase.MiniHBaseCluster.<init>(MiniHBaseCluster.java:91)

當我在我的項目的.jar文件搜索MetricsAssertHelper我找到META-INF/services目錄下的該文件:

jar tvf org/apache/hbase/hbase-hadoop2-compat/1.0.0/hbase-hadoop2-compat-1.0.0-tests.jar | grep MetricsAssertHelper 53 Sat Feb 14 19:43:40 MST 2015 META-INF/services/org.apache.hadoop.hbase.test.MetricsAssertHelper 1337 Sat Feb 14 19:43:40 MST 2015 org/apache/hadoop/hbase/test/MetricsAssertHelperImpl$MockMetricsBuilder.class 3743 Sat Feb 14 19:43:40 MST 2015 org/apache/hadoop/hbase/test/MetricsAssertHelperImpl$MockRecordBuilder.class 6689 Sat Feb 14 19:43:40 MST 2015 org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.class

這是不是.class文件,但是。我想知道是否從.jar文件中缺少MetricsAssertHelper.class文件,因爲那裏有一個'MetricsAssertHelperImpl.class文件'。

這是我的代碼和mvn依賴關係。錯誤發生在HBaseTestingUtility.startMiniCluster()調用上。

private static HBaseTestingUtility utility; 

@Before 
public void setUp() throws Exception { 
    utility = new HBaseTestingUtility(); 
    utility.startMiniCluster(); 
} 


    <dependencies> 

    <dependency> 
     <groupId>org.apache.hadoop</groupId> 
     <artifactId>hadoop-minicluster</artifactId> 
     <version>2.5.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.hbase</groupId> 
     <artifactId>hbase-server</artifactId> 
     <version>1.0.0</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.hbase</groupId> 
     <artifactId>hbase-server</artifactId> 
     <version>1.0.0</version> 
     <type>test-jar</type> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.hbase</groupId> 
     <artifactId>hbase-hadoop2-compat</artifactId> 
     <version>1.0.0</version> 
     <scope>test</scope> 
     <type>test-jar</type> 
    </dependency> 

</dependencies> 

回答

3

問題是,我還需要依賴於hbase-hadoop-compat除了hbase-hadoop2-compat。以下是使用HBaseTestingUtility MiniCluster運行JUnit測試所需的依賴關係的完整列表。

<dependency> 
     <groupId>org.apache.hadoop</groupId> 
     <artifactId>hadoop-minicluster</artifactId> 
     <version>2.5.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.hbase</groupId> 
     <artifactId>hbase-server</artifactId> 
     <version>1.0.0</version> 
     <type>test-jar</type> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.hbase</groupId> 
     <artifactId>hbase-hadoop-compat</artifactId> 
     <version>1.0.0</version> 
     <scope>test</scope> 
     <type>test-jar</type> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.hbase</groupId> 
     <artifactId>hbase-hadoop2-compat</artifactId> 
     <version>1.0.0</version> 
     <scope>test</scope> 
     <type>test-jar</type> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.hbase</groupId> 
     <artifactId>hbase-server</artifactId> 
     <version>1.0.0</version> 
     <scope>test</scope> 
    </dependency> 
+1

所有的依賴應該有測試

+3

爲什麼不只是添加以下內容: org.apache.hbase:HBase的測試-UTIL:1.1.1 ? – user2456600

+0

@ user2456600,你的建議對我有用! – Ahmad

相關問題