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

Missing Gradle project configuration file: .settings/org.eclipse.buildship.core.prefs

Open ai-chen2050 opened this issue 2 years ago • 10 comments

[provide a description of the issue] image

Environment

env:

  • Visual Studio Code version: latest
  • Java extension version: 1.7
  • apple m1 pro
  • latest java pack
  • use Oracle JDK 1.8 to run the program, and use OpenJDK 17 to jdt, as the java server.
Steps To Reproduce

1、use Oracle JDK 1.8 to run the program, and use OpenJDK 17 to jdt, as the java server. 2、compile https://github.com/tronprotocol/java-tron

[Please attach a sample project reproducing the error] Please attach logs

Current Result

Error, Access restriction: The type 'OperatingSystemMXBean' is not API . Can't debug

Expected Result

No error

Additional Informations

java compile server some info as follow:

!ENTRY org.eclipse.jdt.ls.core 4 0 2022-06-24 00:40:59.039 !MESSAGE Error occured while building workspace. Details: message: Access restriction: The method 'OperatingSystemMXBean.getProcessCpuLoad()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 70 message: Access restriction: The method 'OperatingSystemMXBean.getSystemCpuLoad()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 78 message: Access restriction: The method 'OperatingSystemMXBean.getTotalPhysicalMemorySize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 94 message: Access restriction: The method 'OperatingSystemMXBean.getFreePhysicalMemorySize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 102 message: Access restriction: The method 'OperatingSystemMXBean.getTotalSwapSpaceSize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 109 message: Access restriction: The method 'OperatingSystemMXBean.getFreeSwapSpaceSize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 116 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 5 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 44 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 47 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 51 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 3 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 41 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 41 message: Access restriction: The method 'OperatingSystemMXBean.getTotalPhysicalMemorySize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 75 message: Access restriction: The method 'OperatingSystemMXBean.getFreePhysicalMemorySize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 76 message: Access restriction: The method 'OperatingSystemMXBean.getSystemCpuLoad()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 77 message: Access restriction: The method 'OperatingSystemMXBean.getProcessCpuLoad()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 84

!ENTRY org.eclipse.jdt.ls.core 1 0 2022-06-24 00:41:01.712 !MESSAGE >> workspace/executeCommand vscode.java.resolveBuildFiles

ai-chen2050 avatar Jun 24 '22 04:06 ai-chen2050

Help! It's been bothering me two days. @fbricon @Eskibear @gbraad @LightGuard @otaviof

ai-chen2050 avatar Jun 24 '22 04:06 ai-chen2050

Please, do not just at-reply users to get attention. I have no idea what this is about.

Especially as you just filed the issue and expect people to jump to your help. We also have a job and a life.

gbraad avatar Jun 24 '22 04:06 gbraad

Please, do not just at-reply users to get attention. I have no idea what this is about.

Especially as you just filed the issue and expect people to jump to your help. We also have a job and a life.

Oh, sorry, It's github's Recommended. My fault. Have a good day.

ai-chen2050 avatar Jun 24 '22 04:06 ai-chen2050

Recommended? This must be very wrong as it also includes people who aren't members of the organization.

gbraad avatar Jun 24 '22 15:06 gbraad

Really can't help. Using the com.sun.* packages have never been recommended. They're internal classes subject to change anytime.

LightGuard avatar Jun 24 '22 17:06 LightGuard

Recommended? This must be very wrong as it also includes people who aren't members of the organization.

Apologize again. Happy weekend! 😄

ai-chen2050 avatar Jun 25 '22 03:06 ai-chen2050

Really can't help. Using the com.sun.* packages have never been recommended. They're internal classes subject to change anytime.

Thx! okay, I got it. An open-source project that I study recently dependency the com.sun.* packages, I will remind the project side. Have a nice weekend.

ai-chen2050 avatar Jun 25 '22 03:06 ai-chen2050

@ai-chen2050 I can reproduce this. IIUC The problems "xxx is not API" will not stop you from debugging, but you just encountered another error about missing prefs file, which might block you. Here is a workaround:

  1. Set java.import.generatesMetadataFilesAtProjectRoot to true (better in workspace scope)
  2. Press F1 to open the command palette, type Java: Clean Java Language Server Workspace, run this command
  3. After reloading and importing, your project might remain only "xxx is not API" errors, and you might be able to debug, just choose Proceed if there is any tips about the error.

CsCherrYY avatar Jun 27 '22 05:06 CsCherrYY

I can also reproduce it via:

  1. clone https://github.com/spring-projects/spring-petclinic
  2. open it in eclipse, by default, eclipse will import it as a Maven project and generate metadata files
  3. open this project in VS Code, there is a notification shows to choose build tool, choose "Gradle"
  4. The same error appears.

CsCherrYY avatar Jul 04 '22 08:07 CsCherrYY

Thanks for the workaround @CsCherrYY, I had the same issue on GitHub Codespaces and your workaround worked perfectly.

lupino3 avatar Sep 04 '22 08:09 lupino3

@ai-chen2050 I fixed "xxx is not API" errors in a gradle project like this:

build.gradle.kts

plugins {
    eclipse
   // other plugins ...
}

eclipse {
    classpath {
        file {
            whenMerged {
                val classpath = this as org.gradle.plugins.ide.eclipse.model.Classpath
                val jre = classpath.entries.find { 
                    when (it) {
                        is org.gradle.plugins.ide.eclipse.model.Container -> it.path.contains("org.eclipse.jdt.launching.JRE_CONTAINER")
                        else -> false
                    }
                } as org.gradle.plugins.ide.eclipse.model.Container
                jre.accessRules.add(org.gradle.plugins.ide.eclipse.model.AccessRule("accessible", "com/sun/net/**"))
            }
        }
    }
}

wolfg1969 avatar Oct 25 '23 15:10 wolfg1969