Reputation: 11
[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:
Verified Classpath and Project Configuration: I ensured that both .classpath and .project files are correctly configured and match the working project (same as the other project).
Checked Dependencies: I verified that all dependencies are included and correctly specified in build.gradle.
Built the Project: Ran ./gradlew clean build and confirmed that the build was successful without any errors.
Re-imported the Project: Used the Reimport Gradle Project option in VS Code.
Updated launch.json: Ensured the launch.json file correctly specifies the main class and classpath. I also tried this, where you let the debug fail and to click "fix" and choose the main class that pops up, (doesnt happen and let me debug that way anymore)
{
"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": ""
}
]
}
Checked Output and Problems Panels: Reviewed the Output and Problems panels in VS Code for any errors or warnings as well as log file for vscode which doesn't state the reason why its not loading the java project (to what I can see).
Tried asking various LLMs with 0 success.
I have cleaned cache, cleaned java language server, cleaned project, refetched project, re-everything.
Stackoverflow links I have followed without success:
https://github.com/microsoft/vscode-java-debug/issues/692#issuecomment-544364859
How to create a template out of my customized launch.json in vscode?
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