java ClassNotFoundException for org.h2.Driver

前端 未结 13 2373
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 10:40

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

相关标签:
13条回答
  • 2021-01-01 11:21

    In my case(I use sbt) change

    libraryDependencies += "com.h2database" % "h2" % "1.4.196" % Test
    

    to

    libraryDependencies += "com.h2database" % "h2" % "1.4.196"
    
    0 讨论(0)
  • 2021-01-01 11:22

    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>
    
    0 讨论(0)
  • 2021-01-01 11:22

    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.

    0 讨论(0)
  • 2021-01-01 11:22

    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

    0 讨论(0)
  • 2021-01-01 11:23

    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'
    
    0 讨论(0)
  • 2021-01-01 11:25

    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!

    0 讨论(0)
提交回复
热议问题