I am making my first steps with java, after some extensive experiences with python. The script I am running is a simple Java Swing Gui, that compiles and runs fine from the comm
In VS Code just right-click on the src folder and select the "Add folder to Java source path" option. If it didn't' worked, then try to remove it first by selecting "remove the folder from Java source path" and then adding it again.
Hope it works for you.
Since the Microsoft Visual Studio Code ecosystem is rapidly evolving for Java, there is a handy solution that enormously helps to generate - in just a few steps - a functioning Java project structure to use with VS Code.
There are, of course other solutions to work with Java, like NetBeans, but I have always liked VS Code a lot and just waited until something more easy came up to get back to using it.
The quite easy solution I found is using MAVEN. Maven creates the whole project structure and initial configuration files in your home folder and you can immediately open it with VS Code and run it without any hassle.
Of course, you will have to have the Java extensions installed, as explained here.
The solution I found here on the net was a little outdated, so I have made some adaptations.
This is the process on a Linux machine:
Check if you have MAVEN installed
Type into a terminal:
mvn --version
If maven is not installed, the output will suggest the installation command;
Invoke the maven quickstart archetype to generate your new project;
Inside the terminal type or copy:
mvn archetype:generate
This will open a scary list of over 2000 achetypes to choose from. The good news is that if you don't fill in a number, maven-archetype-quickstart will be automatically selected, so just press ENTER.
Choose a version from the list and type in the number: I picked the suggested number = 6
Choose a value for property groupId:
com.mycompany.app
Define a value for property 'artifactId' (this will create the folder in your home directory) :
my-app
Define value for 'version' : 1.0
Define value for property 'package' :
com.mycompany.app
Confirm the options and the project will be generated.
Start VS Code with the new project
In the terminal type :
code ./my-app
Configure a Launch.json file
Configure a Task.json
You are good to go.
I know this is an old question, but anyone who stumbles here and needs a quick and easy fix may find it here. Install the extension: Eclipse New Java Project.
It emulates the behavior of the Eclipse action create Java Project and should produce the results you need.
Just press Ctrl + Shift + P
and type New Java Project (it will pop up after a few letters) and follow the simple directions. (it just asks for the name of the project).
It will create the project and files needed and you won't have to worry about that classpath error.
Then just create your class files as normal in the src
folder of your new project and proceed with your programming!
searching for this i found that vscode right now only recognizes maven projects, or eclipse projects so it needs a .classpath file. So the best option is create the project with maven first and then open with vscode.
This warning is displayed when you open a java file that the redhat.java extension can not determine a classpath for. To get the full benefits of the extension use either a project with maven pom.xml (soon also gradle), or least default eclipse setting files aka .classpath .project files.
i know it's too late but you can simply solve this if you convert your project to eclipse with this simple command mvn eclipse:eclipse
(assuming you are using maven) at your root directory this will add .classpath
file. in this case your src/*
files will be project files
Tested on vscode and coc-java in vim too