Reputation: 3038
I have a deployable maven project where I'm trying to connect to a hive server using JDBC. This is my pom file:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.hive/hive-jdbc -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.test.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
This generates a jar file which has a manifest.mf which is like this:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: test
Class-Path: hive-jdbc-2.1.1.jar hive-common-2.1.1.jar ...
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_72
Main-Class: com.test.Main
Now, when I try to run the jar file using java -jar test.jar
, I get
java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
Why do I get this exception even though the jar file is configured properly in the classpath of the manifest file?
Thanks.
Upvotes: 0
Views: 1435
Reputation: 1882
Make Sure which jar (hive ) do you want .. because it has diferent versions
The old verison jar is
org.apache.hadoop.hive.jdbc.HiveDriver
here is the mvnrepository
and the newest jar is org.apache.hive.jdbc.HiveDriver
here is the new settings
your mistakes is used the old dependency with the new jar name;
Upvotes: 0
Reputation: 3002
You can add maven-dependency-plugin
to copy your dependencies from local or remote repositories to a specified location
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>compile</includeScope>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
or as another option use maven-assembly-plugin
See here
Upvotes: 0
Reputation: 837
The jar referenced in the dependency seems not to be found by java. Probably is not located in the same folder as the target jar.
Depending on what you mean by deploayable maven project you have a couple of possible solutions
Upvotes: 2