12

我下载了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

"在此处输入图像描述

4

4 回答 4

13

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

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

我在用Ubuntu 19.10

于 2020-01-22T00:11:44.860 回答
6

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

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

在行中netbeans_jdkhome编辑路径,如

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

(在askubuntu.com上找到)

于 2020-08-12T18:53:59.473 回答
2

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

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

于 2020-02-12T16:18:28.937 回答
1

如果您将 Maven 用于项目和 OpenJDK,原因可能是您在 maven-compiler-plugin 中定义源和目标选项的方式。我有一个使用 JDK 1.8 构建的小项目,当我迁移它时,maven 编译器插件向我显示了该错误。对我有用的解决方案是在 maven-compiler-plugin 定义中更改和目​​标参数的 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>
于 2021-01-07T21:05:44.427 回答