Vscode-java: Project does not build due to build path being incomplete

Created on 26 Aug 2020  路  10Comments  路  Source: redhat-developer/vscode-java

None of my Java projects are being built properly by the language server.

All my projects are failing, even previously working projects

Fundamentally, I'm getting JRE errors such as The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files.

I'm unable to open standalone Java files, vanilla Java projects and packages, or Maven projects properly.

Here are some things I've tried:

  • Cleaned and restarted the language server workspace multiple times.
  • Set up the runtimes properly according to the guide.
  • Set JAVA_HOME, java.home to jEnv symlinks .jenv/versions/14.0 and directly to the JDK installations themselves /usr/local/Cellar/openjdk/14.0.1/.
  • Repeated the above steps with Java 11 and Java 14.
  • Repeated the above steps with Java 11 Homebrew Cask installation of OpenJDK /Library/Java/JavaVirtualMachines/...
  • Full wipe of VSCode and reinstalled everything, with the same results.
Additional Informations

I'm using jenv to manage my JDKs, and I've enabled the export and maven plugins. Compilation with javac and running with java works just fine.

Environment
  • Operating System: macOS 10.15.6
  • JDK version: 11.0.8, 14.0.1
  • Visual Studio Code version: 1.48.2
  • Java extension version: 0.65.0
Steps To Reproduce
  1. Open a new .java file and define a class.
Log files

redhat.java/client.log.2020-08-26
client.log

Current Result

Plugin is unable to find JRE classes which causes compilation errors for the server.

Expected Result

Plugin should be able to link to JRE classes and compile properly, providing Intellisense without any errors.

Most helpful comment

In VSCode open Command Palette: Java: Clean Java Language Server Workspace -> then restart VSCode fixed this issue for me

All 10 comments

Seems to be related to #483, but the logs produced are different:

{
    "resource": "/Users/bryan/Library/Application Support/Code/User/workspaceStorage/1b823d7928b6aa52270ae85776f4b072/redhat.java/jdt_ws/Labs_ad3d80ac",
    "owner": "_generated_diagnostic_collection_name_#2",
    "code": "0",
    "severity": 8,
    "message": "The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project",
    "source": "Java",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1
}

@snjeza see this exception from the log:

{
  message: '[Error - 10:59:33 PM] 26 Aug 2020, 10:59:33 pm An internal error occurred during: "Update Installed JREs".\n' +
    'null\n' +
    'java.lang.NullPointerException\n' +
    '\tat org.eclipse.jdt.internal.launching.JavaClasspathVariablesInitializer.initialize(JavaClasspathVariablesInitializer.java:50)\n' +
    '\tat org.eclipse.jdt.internal.launching.LaunchingPlugin$VMChanges.rebind(LaunchingPlugin.java:319)\n' +
    '\tat org.eclipse.jdt.internal.launching.LaunchingPlugin$VMChanges.access$0(LaunchingPlugin.java:315)\n' +
    '\tat org.eclipse.jdt.internal.launching.LaunchingPlugin$VMChanges$1.run(LaunchingPlugin.java:301)\n' +
    '\tat org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:41)\n' +
    '\tat org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:736)\n' +
    '\tat org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)\n' +
    '\tat org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)\n' +
    '\tat org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5895)\n' +
    '\tat org.eclipse.jdt.internal.launching.LaunchingPlugin$VMChanges.doit(LaunchingPlugin.java:305)\n' +
    '\tat org.eclipse.jdt.internal.launching.LaunchingPlugin$JREUpdateJob.run(LaunchingPlugin.java:402)\n' +
    '\tat org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)\n',
  level: 'info',
  timestamp: '2020-08-26 22:59:33.198'
}

@bryanmylee can you please share your vscode settings.json?

@bryanmylee Could you try the following:

  • stop VS Code
  • run
rm -rf "/Users/bryan/Library/Application Support/Code/User/globalStorage/redhat.java"
rm -rf "/Users/bryan/Library/Application Support/Code/User/workspaceStorage"
  • start VS Code

@fbricon

{
    "workbench.colorTheme": "Night Owl",
    "workbench.iconTheme": "material-icon-theme",
    "workbench.editor.showTabs": true,

    "breadcrumbs.enabled": true,
    "diffEditor.ignoreTrimWhitespace": false,
    "editor.lineHeight": 20,
    "editor.rulers": [100, 120],
    "editor.fontLigatures": true,
    "editor.suggestSelection": "first",
    "editor.fontFamily": "\"Fira Code\", \"SF Mono\", monospace",
    "editor.minimap.enabled": false,
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "extensions.ignoreRecommendations": true,
    "files.trimTrailingWhitespace": true,
    "scm.diffDecorations": "gutter",
    "scm.inputFontFamily": "editor",
    "terminal.integrated.shell.osx": "zsh",

    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    },

    // Languages
    "java.semanticHighlighting.enabled": true,
    "java.trace.server": "messages",
    "sonarlint.rules": {
        "java:S106": {
            "level": "off"
        }
    },

    "python.languageServer": "Microsoft",
    "python.diagnostics.sourceMapsEnabled": false,

    "emmet.includeLanguages": {
        "javascript": "javascriptreact",
    },
    "eslint.validate": [
        "javascript",
        "svelte",
    ],
    "javascript.updateImportsOnFileMove.enabled": "always",
    "typescript.updateImportsOnFileMove.enabled": "always",
    "[javascript]": {
        "editor.tabSize": 2,
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },

    "r.bracketedPaste": true,

    "vim.leader": ",",
    "vim.easymotion": true,
    "vim.useSystemClipboard": true,
    "vim.useCtrlKeys": true,
    "vim.hlsearch": true,
    "vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": ["<Leader>", "l"],
            "commands": [":nohl"]
        },
        {
            "before": ["<Space>"],
            "after": ["^"]
        },
        {
            "before": ["<CR>"],
            "after": ["$"]
        },
        {
            "before": ["U"],
            "after": ["<C-r>"]
        },
        {
            "before": ["j"],
            "after": ["g", "j"]
        },
        {
            "before": ["k"],
            "after": ["g", "k"]
        },
        {
            "before": ["<C-e>"],
            "after": ["3", "<C-e>"]
        },
        {
            "before": ["<C-y>"],
            "after": ["3", "<C-y>"]
        },
        {
            "before": ["Z", "Z"],
            "commands": [":wq"]
        },
        {
            "before": ["g", "a"],
            "commands": ["wwm.aligncode"]
        },
        {
            "before": ["g", "H"],
            "commands": ["editor.action.quickFix"]
        },
        {
            "before": ["g", "<Space>"],
            "commands": ["editor.action.sourceAction"]
        },
        {
            "before": ["]", "g"],
            "commands": ["editor.action.marker.prev"]
        },
        {
            "before": ["[", "g"],
            "commands": ["editor.action.marker.next"]
        },
    ],
    "vim.easymotionMarkerBackgroundColor": "darkslategray",
    "vim.easymotionMarkerForegroundColorOneChar": "white",
    "vim.easymotionMarkerForegroundColorTwoChar": "lightgray",
    "vim.easymotionMarkerFontWeight": "normal",
    "vim.replaceWithRegister": true,
    "vim.camelCaseMotion.enable": true,
}

@snjeza I've done so and I am still getting the same results. I've tried wiping and reinstalling VSCode, including its support files, if that helps.

For some additional context, the language of coc-java for coc.nvim works with my nvim install.

@bryanmylee could you add the following property to your settings.json:

"java.home": "/usr/local/Cellar/openjdk/14.0.1/",

and send your logs

Added the java.home property to my brew install of openjdk, but still facing the same issues.

client.log

I am also getting this issue.
I've tried everything above, as well as reverting to older versions of the extension and running mvn clean eclipse:clean eclipse:eclipse to try force recreation of project settings with no success. Also tried various JDKs, including openJDK and Adopt.

In VSCode open Command Palette: Java: Clean Java Language Server Workspace -> then restart VSCode fixed this issue for me

Having the same problem on a Linux, I wonder how to verify that the a Java environment was indeed identified. Using the command "Java: Configure Java Runtime" and looking at the tab "Java tooling Runtime", it is empty despite having

"java.home": "/home/me/tools/Store/jdk-11",
  "java.configuration.runtimes": [
    {
      "name": "JavaSE-11",
      "path": "/home/me/tools/Store/jdk-11"
    },
    {
      "name": "JavaSE-1.8",
      "path": "/home/me/tools/Store/jdk-8",
      "default": true
    }
  ]

in my settings.json. Though I do see a java process with some .../.vscode/extensions/redhat.java-0.74.0/... parts on the command line, which seems to indicate this part is actually working.

I could not find this mentioned anywhere, but the path is correct if it contains ./bin/javac and the other java commands?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sfariaNG picture sfariaNG  路  3Comments

gorkem picture gorkem  路  4Comments

ulongx picture ulongx  路  4Comments

danielcalvogonzalez picture danielcalvogonzalez  路  3Comments

roben picture roben  路  4Comments