0

I'm getting the above error when I try to execute the following command.

java -cp target/helloHBase-1.0-SNAPSHOT.jar HBaseIA.TwitBase.UsersTool add TheRealMT "Mark Twain" samuel@clemens.org abc123

I'm using IntelliJIdea IDE and all my maven 'clean', 'install' and 'package' commands give "Build Success" message.

The directory structure of the project is provided below. I've already imported the hbase jar files to my project as external libraries in IntelliJ.

enter image description here

Complete error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/client/HTablePool
        at HBaseIA.TwitBase.UsersTool.main(UsersTool.java:22)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.client.HTablePool
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more

pom.xml provided below.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>hbase</groupId>
    <artifactId>helloHBase</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase-client -->
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>1.1.2</version>
        </dependency>
    </dependencies>  
</project>
CoolCK
  • 416
  • 5
  • 16
  • Are the hbase jar files compiled as part of the helloHBase-1.0-SNAPSHOT.jar? – Alan Kavanagh May 24 '19 at 23:07
  • If you're running java directly, you also have to setup you classpath. Which, can be tedious if you have to do it by hand. If you use the integrated intellij run/debug command, it will setup your classpath for you. – hooknc May 24 '19 at 23:11
  • Hi @hooknc I want to execute the jar file I created from 'mvn package' command, with the above command I mentioned. – CoolCK May 24 '19 at 23:15
  • @AK47, I already imported hbase-client library as an external library to IntelliJ and included it in the pom.xml – CoolCK May 24 '19 at 23:15
  • 1
    @CoolCK yep it's imported within IntelliJ, but you're running it on the cmd line. Is it packaged within the jar? – Alan Kavanagh May 24 '19 at 23:23
  • @AK47 , I'm newbie to maven. How may I know if it is packaged ? I already executed mvn clean, mvn build and mvn package commands. Do I have to separately include the hbase jar file in the new jar file ? – CoolCK May 24 '19 at 23:26
  • @SiKing , would you mind share how should I update my pom.xml . I believe I have to add build tags (and others) to my pom.xml according to the post. – CoolCK May 24 '19 at 23:35
  • 1
    `maven package` doesn't create an executable jar file. If you're making a jar, it just takes your code and then packages it up in a jar file. This means that you will have to set you classpath when running your application. There are ways of creating an executable jar file, but you'll need to use a Spring maven plugin: https://www.baeldung.com/executable-jar-with-maven – hooknc May 28 '19 at 15:42

0 Answers0