使用 Oracle JDK 1.7 时出现“错误:找不到 java.nio.file.Paths”

使用 Oracle JDK 1.7 时出现“错误:找不到 java.nio.file.Paths”

我想尝试 Oracle 新 JDK 1.7 中推出的一些功能。我关注了以下帖子:-Oracle JDK 1.7但这篇文章似乎没有帮助。

我试图获取java.nio.file.Paths类文件的结构,但出现以下错误:-

buffer@ankit:~$ javap java.nio.file.Paths ERROR:Could not find java.nio.file.Paths

然而,我可以轻松获得有关 JAVA SE 1.6 之前的类结构的信息,下面是一个例子:-

buffer@ankit:~$ javap java.lang.Object
Compiled from "Object.java"
public class java.lang.Object{
    public java.lang.Object();
    public final native java.lang.Class getClass();
    public native int hashCode();
    public boolean equals(java.lang.Object);
    protected native java.lang.Object clone()       throws java.lang.CloneNotSupportedException;
    public java.lang.String toString();
    public final native void notify();
    public final native void notifyAll();
    public final native void wait(long)       throws java.lang.InterruptedException;
    public final void wait(long, int)       throws java.lang.InterruptedException;
    public final void wait()       throws java.lang.InterruptedException;
    protected void finalize()       throws java.lang.Throwable;
    static {};
}

运行 java -version 得到以下结果:-

buffer@ankit:~$ java -version java version "1.7.0_09" Java(TM) SE 运行时环境(build 1.7.0_09-b05)Java HotSpot(TM) 64 位服务器 VM(build 23.5-b02,混合模式)

系统信息

buffer@ankit:~$ sudo update-alternatives --config java
[sudo] password for buffer: 
There are 4 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual mode
  3            /usr/lib/jvm/jdk1.7.0_09/                        1         manual mode
* 4            /usr/lib/jvm/jdk1.7.0_09/bin/java                1         manual mode



buffer@ankit:~$ sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk-amd64/bin/javac   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/bin/javac   1061      manual mode
* 2            /usr/lib/jvm/jdk1.7.0_09/bin/javac            1         manual mode



buffer@ankit:~$ sudo update-alternatives --config javaws
There are 3 choices for the alternative javaws (providing /usr/bin/javaws).

  Selection    Path                                              Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaws   1060      manual mode
* 3            /usr/lib/jvm/jdk1.7.0_09/bin/javaws                1         manual mode

目录结构/usr/lib/jvm/如下:-

buffer@ankit:~$ ls -l /usr/lib/jvm/
total 24
lrwxrwxrwx 1 root   root     24 Dec  2  2011 default-java -> java-1.6.0-openjdk-amd64
drwxr-xr-x 4 root   root   4096 Nov  8 16:24 java-1.5.0-gcj-4.6
lrwxrwxrwx 1 root   root     24 Dec  2  2011 java-1.6.0-openjdk -> java-1.6.0-openjdk-amd64
lrwxrwxrwx 1 root   root     20 Oct 25 00:01 java-1.6.0-openjdk-amd64 -> java-6-openjdk-amd64
lrwxrwxrwx 1 root   root     20 Oct 25 06:59 java-1.7.0-openjdk-amd64 -> java-7-openjdk-amd64
lrwxrwxrwx 1 root   root     24 Dec  2  2011 java-6-openjdk -> java-1.6.0-openjdk-amd64
drwxr-xr-x 7 root   root   4096 Nov  8 16:24 java-6-openjdk-amd64
drwxr-xr-x 3 root   root   4096 Nov  8 16:24 java-6-openjdk-common
drwxr-xr-x 5 root   root   4096 Nov  8 05:48 java-7-openjdk-amd64
drwxr-xr-x 3 root   root   4096 Nov  8 05:48 java-7-openjdk-common
drwxr-xr-x 8 buffer buffer 4096 Sep 25 09:08 jdk1.7.0_09

任何帮助都将非常感激。

答案1

Java 可执行文件

Java 由许多单独的可执行文件组成 -javac并且javaws是最常见的。

javap另一个是 - 安装 Java 时,您需要单独确保每个可执行文件都已注册 - 您可以使用update-alternatives

sudo 更新替代方案 --install “/usr/bin/java” “javap” “/usr/lib/jvm/jdk1.7.0/bin/javap” 1
sudo 更新替代方案 --config javap

如果您希望在开发过程中使用它们,这个答案会为您提供可以注册的各个可执行文件的列表。

或者 - 您可以使用第三方 PPA,例如webupd8- 但作为开发人员,我喜欢了解问题并根据我的需要定制我的配置。

答案2

通过这个PPA安装

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html

相关内容