2
votes

In a programe,

import java.nio.file.*;

Gives error - The import java.nio.file cannot be resolved

Following other threads, I changed JDK Compliance Level to 1.7, also added

-vm
/home/user/jdk1.7.0_79/bin/java

to eclipse.ini

Eclipse -> About -> Installation details has following lines -

java.home=/home/user/jdk1.7.0_79/jre

java.library.path=/home/user/jdk1.7.0_79/jre/lib/i386/server:/home/user/jdk1.7.0_79/jre/lib/i386:/home/user/jdk1.7.0_79/jre/../lib/i386:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386::/usr/java/packages/lib/i386:/lib:/usr/lib

java, javac versions -

user$ ~/jdk1.7.0_79/jre/bin/java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) Server VM (build 24.79-b02, mixed mode) user$ ~/jdk1.7.0_79/bin/java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) Server VM (build 24.79-b02, mixed mode) user$ ~/jdk1.7.0_79/bin/javac -version javac 1.7.0_79

How should I correctly import java.nio.file.*?

1
You probably mean import java.nio.file.*;? java.nio.file is a package, not a class and can therefore not be imported.Turing85
@Turing85 Thanks, edited the question.user13107
Isnt the Java home just - /home/user/jdk1.7.0_79 ? I guess you added jre as well to it. Can you change the java.home to point to /home/user/jdk1.7.0_79 and try again ?Kalyan Chavali
@KalyanChavali I don't know. It came by default. Even if I add -Djava.home=/path/to/jdk to ini and restart eclipse it still shows the jre pathuser13107

1 Answers

6
votes

Solved it!

Even after doing all the recommended things it wasn't working. Finally saw a setting in another thread that I hadn't tried till now.

Project -> Properties -> Java Build Path -> Libraries -> Add Library -> JRE System Library -> Select Workspace Default (jdk 1.7*)

Done.

So even when eclipse installation details configuration may show all the correct numbers, we still have to explicitly add 1.7 library from project properties.