18

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",
        },
    ]
}
7
  • 1
    New update on vs code asks for running/compiling the project files if you trust it. You may choose not to trust the project, so it can't run/compile the files automatically code.visualstudio.com/docs/editor/workspace-trust Commented Jun 17, 2021 at 21:11
  • Yes, I received a pop up and checked, Yes, I trust the authors, but i still get the gradle error and vscode is unable to find my java project. Commented Jun 17, 2021 at 21:18
  • It does prompt me with, "The workspace contains Java projects. Would you like to import them?", but seems to fail to import them. Commented Jun 17, 2021 at 21:22
  • @LeadVaxeral what version of Java and what version of gradle are you using? Commented Jun 17, 2021 at 21:24
  • Sounds like a mismatch in versions Commented Jun 17, 2021 at 21:24

6 Answers 6

20

Run Java: Clean Java Language Server Workspace on command palette

  • In my case, I have no settings files like .project, ./settings/...files
Sign up to request clarification or add additional context in comments.

2 Comments

Why does this work - does VS Code (Java extension) need the mentioned settings files?
Thank you, it worked for me, but without modifying the settings.json file
2

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

Comments

1

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

5 Comments

Java extension needs JDK11 or recent version to support so if you set jdk1.8 as java.home, the extension won't work well.
But i never said to do that though i said to set a run config for java 11+ with the same path as the home path @MollyWang Just as i have it in the second json file i posted.
But i guess the clarification is fine. Thank you @MollyWang.
What da hellll man.
Sorry im a bit crude. I didnt mean to come off that way.
1

I tried all the methods mentioned above, but unfortunately, none of them worked. I have an existing Java project and I've installed the "Extension Pack for Java", but VSCode still couldn't recognize this Java project.

Eventually, I found a solution. I closed the current Java project, opened a new VSCode window, and directly opened the folder of the Java project. After doing this, everything went back to normal!

If you're facing a similar issue, you might want to give this method a try.

Comments

0

I had a similar problem. I opened a multi-module Maven project in vscode. vscode recognized it as a Java project (I see all modules in "Java Projects" and "Maven" tabs), however nothing was compiled.

I noticed that there was no ".project" or ".classpath" file in the folder.

The solution I found: I opened the same project with Eclipse. Eclipse created the ".project" and ".classpath" files. Than I opened again the project in vscode, and now vscode compiles everything correctly! (Not a beautiful solution, I know).

Comments

0

None of the previously posted answers fixed my issue, though it seemed like I was facing the same issue.

I managed to get vscode to recognize the java project by choosing this option in the command palette: Java: Configure Java Runtime. Vscode said there was no Java project in the workspace to configure, and vscode asked if I wanted to open a java project. I chose the same project as was already open. Vscode asked if I wanted to save the existing workspace configuration. I chose not to do so (due to how broken it clearly was!). Then the exact same project was opened by vscode and vscode recognized it as a java project. I opened a few files and now I am seeing the red squiggly lines and 37 problems in the problems tab.

I am so confused but so relieved. Hope this will help someone else.

New contributor
Kelie Berendt is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.