I checked this question and many other posts to help me resolve my issue, but nothing worked.
I trying to open an existing Java Project from Eclipse in vscode. The project was opened successfully in Eclipse 2021-06 and I fixed the referenced libraries by selecting the JAR libraries under lib/
folder and right-click - configure build batch - add select add to build path. Then the file .classpath
was updated automatically. Then I had to download JDK 11 (needed for vscode) and JDK 1.8 needed for the Java project. I managed to work with eclipse to set the JDK correctly and all worked fine. I was able to compile the project, export the result JAR and deploy and all worked well.
I am having trouble to open this project in vscode using Open Java Project
option. I am facing issues adding referenced libraries this Java project as it is a managed project (since it was created in Eclipse). When I try to add the libraries using vscode UI, I am getting mixed results and sometimes it is not working and the build fails. I was surprised as in some instances, things just work, and then they don't.
I tried to update .classpath
file in vscode and still same issues. When I try to add the libraries from Referenced Libraries (Read Only)
under JAVA PROJECTS
tree in vscode by clicking +
, it has no effect. This step will modify the file settings.json
under .vscode
folder by adding the relevant values to the property "java.project.referencedLibraries"
.
I am confused about how to configure the referenced libraries for Java projects in vscode. Following is a summary of questions:
.classpath
file and by modifying settings.json
file? Which one will win?.classpath
and .project
files are not showing in vscode explorer view? It will only show when you open the file in vscode from the Windows File Explorer.Configure Classpath
but it is read-only, which I think it is the same as the .classpath
file. Is there a way to change it from vscode UI?.classpath
file or when I removed the classpathentry
lines from the .classpath
file, the node 'Referenced Libraries (Read Only)' under JAVA PROJECTS
in vscode view was removed. Why?See the snapshots below for more details.
I appreciate your help.
Basically speaking, java extension looks for jars from Referenced Libraries.
Here're my answers to your questions:
Right click the jar and choose copy relative path
then add it to settings, click the refresh button then the added jar should be displayed under the option Referenced Libraries:
The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user classes. When it comes to add jars, settings java.project.referencedLibraries
wins.
No way to select jar folders but you can use keyboard shortcuts to select all jars then add them.
There's a setting called "java.configuration.checkProjectSettingsExclusions"
, and it's true by default, so .project
and .classpath
won't be shown in VS Code.
The command Java: Configure Classpath works on my machine, which can customize current project.
My guess is when you open a new project, vscode popped up a window and ask you if trust it, and you chose Not, then project is read-only. Trusting the workspace then try the command Java: Configure Classpath again, it should be writeable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With