【问题标题】:Netbeans IDE 11 cannot access java.lang Fatal Error: Unable to find package java.lang in classpath or bootclasspathNetbeans IDE 11 无法访问 java.lang 致命错误:无法在类路径或引导类路径中找到包 java.lang
【发布时间】:2019-09-28 09:15:47
【问题描述】:

我下载了 netbeans ide 11 并尝试做一个示例 hello world 项目,但它给了我错误“无法访问 java.lang 致命错误:无法在类路径或引导类路径中找到包 java.lang” 我尝试了一些堆栈溢出的解决方案,但没有奏效。

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

/**
 *
 * @author ahmad
 */
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Hello");
    }
    
}

主要错误是 " 无法访问 java.lang 致命错误:无法在类路径或引导类路径中找到包 java.lang

"

【问题讨论】:

  • 请使用工具 > Java 平台的屏幕截图更新您的问题。

标签: java netbeans-11


【解决方案1】:

我也有同样的问题。 使用手动设置默认jdk解决。

  1. 从<install_dir>/netbeans/etc打开netbeans.conf
  2. 为netbeans_jdkhome属性设置JDK主路径

我正在使用Ubuntu 19.10

【讨论】:

  • 如果您不确定您的 JDK 路径,请运行 sudo update-java-alternatives -l 列出这些。此外,请确保您已将主类设置为项目属性下的入口点。见:stackoverflow.com/questions/20601845/…
【解决方案2】:

退出 netbeans 后编辑配置文件 netbeans.conf 使用

nano ~/netbeans-11.2/netbeans/etc/netbeans.conf

在netbeans_jdkhome这一行编辑路径

netbeans_jdkhome="/usr/lib/jvm/java-11-openjdk-amd64"

(发现于askubuntu.com)

【讨论】:

    【解决方案3】:

    在完全卸载我的发行版 Netbeans 版本后,我求助于将 Netbeans 11 LTS 版本从 https://netbeans.apache.org/download/nb110/nb110.html 安装到 /usr/share/netbeans。这似乎已经解决了 IDE 中的问题。该程序现在似乎也编译和运行得更快了。

    我在使用 Ubunutu/Mint 存储库中的 Netbeans IDE 时遇到了非常相似的问题,该存储库仍在版本 10 上,而开放的 JDK 是版本 11。我无法让 IDE 无错误地显示 - 但程序将从以下位置编译和运行命令行很好。

    【讨论】:

      【解决方案4】:

      如果您在项目中使用 Maven 和 OpenJDK,原因可能是您在 maven-compiler-plugin 中定义源和目标选项的方式。我有一个使用 JDK 1.8 构建的小项目,当我迁移它时,maven 编译器插件向我显示了该错误。 对我有用的解决方案是在 maven-compiler-plugin 定义中更改 source 和 target 参数上的 java 版本格式:

      之前:

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
          <configuration>
              <source>1.7</source>
              <target>1.7</target>
              <compilerArguments>
                  <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
              </compilerArguments>
              <showDeprecation>true</showDeprecation>
          </configuration>
      </plugin>
      

      之后:

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
          <configuration>
              <source>7</source>
              <target>7</target>
              <compilerArguments>
                  <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
              </compilerArguments>
              <showDeprecation>true</showDeprecation>
          </configuration>
      </plugin>
      

      【讨论】:

        【解决方案5】:

        在同一个方向安装netbeans和jdk。

        【讨论】:

          猜你喜欢
          • 2012-12-17
          • 1970-01-01
          • 2015-05-10
          • 1970-01-01
          • 2014-10-09
          • 2012-09-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多