1

I downloaded some code from net and opened it in Eclipse. The problem is my Eclipse says

The import org.h2 cannot be resolved

for following code:

import org.h2.tools.Server;

I am learning Java and that was a sample code. I'm using jdk1.8.0_40. I cleaned my project but it still there!

rtruszk
  • 3,902
  • 13
  • 36
  • 53
user2448215
  • 35
  • 1
  • 6

2 Answers2

10

Personally, I changed the h2 dependency on pom.xml

It was

<dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
</dependency>

I removed the scope and it found the Server package

<dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
</dependency>

A good explanation on why this is happening on runtime here: Maven : what is the "runtime" scope purpose?

Manuel Pap
  • 1,309
  • 7
  • 23
  • 52
2

Actually, this means your code requires a so called 3rd party library which is not part of the jdk. H2 is a java based database. To remove this error, download the current version of the h2 database driver and do the following in eclipse - open context menu on your project, choose the properties ( last entry). Search for "build path", choose the third tab and add the download driver (should be a jar file, maybe packed in a zip) to your project.

Cannot better describe this now, I am on my mobile.

swinkler
  • 1,703
  • 10
  • 20