vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Project does not build due to build path being incomplete

Open bryanmylee opened this issue 5 years ago • 21 comments

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.

bryanmylee avatar Aug 26 '20 15:08 bryanmylee

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
}

bryanmylee avatar Aug 26 '20 15:08 bryanmylee

@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?

fbricon avatar Aug 26 '20 15:08 fbricon

@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

snjeza avatar Aug 26 '20 17:08 snjeza

@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,
}

bryanmylee avatar Aug 27 '20 07:08 bryanmylee

@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 avatar Aug 27 '20 07:08 bryanmylee

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

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

and send your logs

snjeza avatar Aug 27 '20 22:08 snjeza

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

client.log

bryanmylee avatar Aug 29 '20 06:08 bryanmylee

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.

Rupert-117 avatar Sep 14 '20 10:09 Rupert-117

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

marcelweigle avatar Jan 15 '21 11:01 marcelweigle

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?

HaraldKi avatar Jan 31 '21 16:01 HaraldKi

In my case the resolution was something different. My project needs Java 8 and pom.xml has this.

<plugin>
	<artifactId>maven-compiler-plugin</artifactId>
	<version>3.7.0</version>
	<configuration>
		<source>1.8</source>
		<target>1.8</target>
	</configuration>
</plugin>

I have both JDK 8 and 15 installed and VS Code correctly detects both.

image

However, when the project was opened in VS Code it did not choose the JDK correctly to compile the project. I had to manually fix this.

image

After that the project compiled fine and the The project was not built since its build path is incomplete error went away.

It is worth noting that VS Code doesn't have this problem if you specify the JDK version using properties:

<properties>
	<maven.compiler.source>1.8</maven.compiler.source>
	<maven.compiler.target>1.8</maven.compiler.target>
</properties>

We are switching to this from setting configuration of the maven-compiler-plugin.

bibhas2 avatar Apr 14 '21 15:04 bibhas2

I had the same problem, and I don't know what to do. Did you solve it?

zhanghuanhuanzhang avatar Feb 08 '22 04:02 zhanghuanhuanzhang

<properties>
	<maven.compiler.source>1.8</maven.compiler.source>
	<maven.compiler.target>1.8</maven.compiler.target>
</properties>

Thanks for this! Like many other people, my project builds fine on the command line but the Redhat plugin trips over it. Setting the properties helped me.

cowlike avatar Feb 19 '22 21:02 cowlike

I had the same problem, and I’m also using Homebrew-installed OpenJDKs. After some trial and error, finally I found the solution: just point OpenJDK to /usr/local/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home instead of /usr/local/opt/openjdk@11. So the Java runtime configuration looks like this:

"java.configuration.runtimes": [
  {
    "name": "JavaSE-1.8",
    "path": "/usr/local/opt/openjdk@8/libexec/openjdk.jdk/Contents/Home",
  },
  {
    "name": "JavaSE-11",
    "path": "/usr/local/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home",
    "default": true,
  },
  {
    "name": "JavaSE-17",
    "path": "/usr/local/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home",
  },
  {
    "name": "JavaSE-18",
    "path": "/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home",
  },
],

Note: It’s recommended to point OpenJDK to /usr/local/opt/openjdk@11 instead of /usr/local/Cellar/openjdk@11/11.0.5 because the former is always a symlink to the latest version of the formula (in this case, /usr/local/Cellar/openjdk@11/11.0.5) and will survive future minor and patch version updates.

Note 2: If you are just using java, javac, jar or other binaries from the the OpenJDK on the command line, you can just export JAVA_HOME=/usr/local/opt/openjdk but for VS Code to make full use of the OpenJDK you need to point it to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home because that’s where the jmods directory resides.

luangong avatar Apr 28 '22 03:04 luangong

rm -rf "/Users/bryan/Library/Application Support/Code/User/globalStorage/redhat.java" rm -rf "/Users/bryan/Library/Application Support/Code/User/workspaceStorage"

This work

SeFeX avatar May 03 '22 16:05 SeFeX

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

This work for me, thanks.

miqueiaspcoelho avatar Dec 09 '22 22:12 miqueiaspcoelho

@luangong Thanks, that solved my issue. I had to do this:

  "java.configuration.runtimes": [
    {
      "name": "JavaSE-11",
      "path": "/opt/homebrew/Cellar/openjdk@11/11.0.18/libexec/openjdk.jdk/Contents/Home",
    },
    {
      "name": "JavaSE-17",
      "path": "/opt/homebrew/Cellar/openjdk@17/17.0.6/libexec/openjdk.jdk/Contents/Home",
      "default": true
    },
    {
      "name": "JavaSE-19",
      "path": "/opt/homebrew/Cellar/openjdk/19.0.1/libexec/openjdk.jdk/Contents/Home",
    }
  ],

charafsalmi avatar Jan 30 '23 15:01 charafsalmi

It's worked for me add this two props on my settings.json:

   ...


  "java.jdt.ls.java.home": "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home",
  "java.configuration.runtimes": [
    {
      "name": "JavaSE-17",
      "path": "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home"
    }
  ]

ghost avatar Sep 13 '23 01:09 ghost

It's worked for me add this two props on my settings.json:

   ...


  "java.jdt.ls.java.home": "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home",
  "java.configuration.runtimes": [
    {
      "name": "JavaSE-17",
      "path": "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home"
    }
  ]

The above also worked for me. Does anyone know why this error suddenly occurred sometime late yesterday (UTC/GMT +2 hours)?

C-Vilen avatar Sep 13 '23 10:09 C-Vilen

It's worked for me add this two props on my settings.json:

   ...


  "java.jdt.ls.java.home": "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home",
  "java.configuration.runtimes": [
    {
      "name": "JavaSE-17",
      "path": "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home"
    }
  ]

Thanks mate, worked for me

Ferdous123 avatar Sep 14 '23 07:09 Ferdous123

Adding a pom.xml at project root worked for me.

Just do:

<properties>
	<maven.compiler.source>1.8</maven.compiler.source>
	<maven.compiler.target>1.8</maven.compiler.target>
</properties>

PS: I did change the maven.compiler.source and maven.compiler.target values I should add.

tonyoruovo avatar Dec 06 '23 09:12 tonyoruovo