简体   繁体   中英

Visual Studio Code not recognizing java project

VS Code is not recognizing my java project. The project is template code for a minecraft mod found here . Ive installed the plugins

  • "Debugger for Java"
  • "Java Extension Pack"
  • "Language Support for Java by Redhat"
  • "Java Test Runner"
  • "Project Manager for Java"

I also get an error related to gradle.

Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.0.2-bin.zip'.
java.io.StreamCorruptedException: invalid type code: 00
invalid type code: 00

And here is my settings.json file

{
    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    },
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "java.configuration.updateBuildConfiguration": "interactive",
    "java.home": "/usr/lib/jvm/java-16-openjdk-amd64",
    "java.configuration.runtimes": [
        {
          "name": "JavaSE-1.8",
          "path": "/usr/lib/jvm/java-8-openjdk-amd64",
          "default": true
        },
    ]
}

I have no code completion for my Java files. Before it was working and in the lower right corner of visual studio it displayed the java version i was using but now it just says Java. I'm assuming its because there is a problem with gradle and thus cannot figure out my java version. Thank you for your time.

Update: This seems to work and give me auto completion but i stil get a gradle related error mention above.

{
    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    },
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "java.configuration.updateBuildConfiguration": "interactive",
    "java.home": "/usr/lib/jvm/java-16-openjdk-amd64",
    "java.configuration.runtimes": [
        {
          "name": "JavaSE-1.8",
          "path": "/usr/lib/jvm/java-8-openjdk-amd64",
          "default": true
        },
        {
            "name": "JavaSE-16",
            "path": "/usr/lib/jvm/java-16-openjdk-amd64",
        },
    ]
}

For anyone who is stuck with the same problem as me make sure your settings.json file looks similar to mine including both java 1.8 run config and the java 11+ run config same as the one specified as the home path. That should fix the java language level. The gradle error you can ignore but you must use gradle runClient instead of the run configuration that vscode provides. Happy modding:D

In my case, I solved the problem by creating a new Java Project, and comparing the files that were generated. In particular I found missing entries in .project

<buildSpec>
        <buildCommand>          <!-- was missing -->
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature> <!-- was missing -->
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
    </natures>

also some settings in .settings/org.eclipse.jdt.core.prefs were missing but they did not immediately fixed the problem until I added the above.

Of course, you need to clean the workspace everytime you make a change (with the ... -> clean workspace or the command palette Java > clean Java Language server workspace

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM