.java is not on the classpath of project, only syntax errors are reported

Viewed 25643

I could not find a proper answer to this error in other posts. I am using Maven for building my project in VS Code and whenever I create a class this error appears. Do I need to do anything with .classpath file? Correct me if I am mistaken, this error is pointing out that the class is not recognized by the .classpath file in which it belongs to, so I have to address it in that file.

Tnx

6 Answers

It seems like no one else knew it!

The problem was regarding "folder convention" and "maven-dependency-plugin". As I created my Maven project with the line below via windows command line, maven did not install dependency-plugin and that created the first problem.

Second, what I meant by "folder convention" was, deleting "java" folder which is created by executing bellow Maven command line, caused me a problem since Maven compiler does not find any Java project to go to and execute codes. Deleting Java folder will also lead to the error above because no Java file is recognized, so no java files will be added to .classpath folder respectively.

mvn archetype:generate -DgroupId=name -DartifactId=name -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

I had the same problem.

From Welcome screen, go to Student-->Getting Started-->FAQ-->Find the "Why do I see tons of problems and red squiggles?" portion and click " Clean Workspace". That fixed my problem.

I have the same problem. Just close the vscode and open it again. Hope it works

Since i was using a different structure from what the maven project expected i had to manually change the .classpath file from pointing to the wrong folder. Only after this that my imports started to be correctly resolved.

Original:

<classpath>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    ...

Modified path attribute:

<classpath>
    <classpathentry kind="src" output="target/test-classes" path="src">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    ...

i have noticed when i open multiple cmd to type "code . " this error occurs try to close all CMD's and reopen project i think it will go away

I had the same problem and it was just about folder structure of vscode. when you created java file, it would have created a .java file (and maybe a .class file). Just simply move the .java file into src folder and .class file into bin folder and the problem is solved.

link of screenshot if you need

Related