I am trying to use H2 to connect to a database in Java (using Eclipse as the IDE). The sample does (below) throws a ClassNotFoundException
. The thing is, I
In my case(I use sbt) change
libraryDependencies += "com.h2database" % "h2" % "1.4.196" % Test
to
libraryDependencies += "com.h2database" % "h2" % "1.4.196"
Recently I encountered the java.lang.ClassNotFoundException: org.h2.Driver
exception in IntelliJ IDEA 2017.2 EAP while using the latest version (1.4.196) of H2 driver. The solution was to downgrade to 1.4.195 that worked.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.195</version>
<scope>test</scope>
</dependency>
I was having the following error (using Intellij)
java ClassNotFoundException for org.h2.Driver
Solved it by removing the scope from my pom.
was:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
<scope>test</scope>
</dependency>
changed to:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
</dependency>
This type of error will come when we are implementing Maven Quickstart project as a dependency to another project. Mostly occurs as test only for junit. So in application it will not work.
I am working with intelliJ. I had the "h2-1.4.200" in the lib folder. I tried every suggestion, ranging from , to . Strangely, my problem got solved only by going to these places : Project Structure -> Artifact -> Output Layout -> Available Elements and then expanding the content of the folder and then right click on "h2-1.4.200" and finally select "Extract Into Output Root". :) The strange solution
If you use Gradle change dependency in build.gradle:
testCompile group: 'com.h2database', name: 'h2', version: '1.4.199'
to
compile group: 'com.h2database', name: 'h2', version: '1.4.199'
I use sbt. In build.sbt, I removed the "h2" dependency and included this instead: "com.h2.database" % "h2" % "1.4.200" And it worked!