Linus Wass
Linus Wass

Reputation: 11

VS Code Not Recognizing Java Project and Main Class Not Found Error [Debug]

[Note, Java 8 and Gradle 3 is required for the project] I'm working on a Java project in VS Code, but it's not being recognized as a Java project. When I try to run my main class, I get the following error:

C:\Users\543333\Desktop\Work\XXX> cmd /C "C:\Users\543333\.sdkman\candidates\java\8.0.372-zulu\bin\java.exe -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:54008 -Djava.library.path=C:\Users\543333\Desktop\Work\XXX/libs -Dvisualvm.display.name=XXX%PID -Dvisualvm.id=1736926826626 -cp C:\Users\543333\AppData\Roaming\Code\User\workspaceStorage\eb7fd0964a13a4e0e5ba0ab8a3a342d7\redhat.java\jdt_ws\jdt.ls-java-project\bin Mainclass "
Error: Could not find or load main class Mainclass

I have two projects which are essentially the same. One is able to load in VS Code without any issues, and the other is not. Both projects share the same launch.json, settings.json, .classpath, and .project files (with correct directories specified). They both have a build.gradle in the root directory and both pass the ./gradlew clean build command. This one that has the problem, has been able to run before, but suddenly when re-cloning the project, it stopped working and haven't been able to run it since.

The configuration for the projects are as follows:

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" path="src/main/resources"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
    <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
    <classpathentry kind="output" path="build/classes/main"/>
</classpath>

.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>Main class</name>
    <comment>Project MainClass created by Buildship.</comment>
    <projects></projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments></arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
            <arguments></arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
    <filteredResources>
        <filter>
            <id>1734344530434</id>
            <name></name>
            <type>30</type>
            <matcher>
                <id>org.eclipse.core.resources.regexFilterMatcher</id>
                <arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
            </matcher>
        </filter>
    </filteredResources>
</projectDescription>

[Reason why there is stuff for Eclipse is because the project has been ran on the IDE before, but I am picking up a project that is 10+ years old with 0 development since then...]

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug Main class",
            "request": "launch",
            "mainClass": "Specified directory.Mainclass",
            "console": "integratedTerminal",
            "vmArgs": "-Djava.library.path=${workspaceFolder}/libs",
            "args": "",
            "classpath": "${workspaceFolder}/build/classes/main"
        }
    ]
}

OBS:

I followed the following:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug Current File",
            "request": "launch",
            "mainClass": "${fileBasenameNoExtension}",
            "projectName": "",
            "console": "integratedTerminal",
            "vmArgs": "-Djava.library.path=${workspaceFolder}/libs",
            "args": ""
        }
    ]
}

Stackoverflow links I have followed without success:

I followed a few more but I don't find them now. Either way, I don't seem to find the solution to what this can be

Because in this case, it can just be launch.json, settings.json, .classpath, .project right?

Upvotes: 1

Views: 63

Answers (0)

Related Questions