Visual Studio Code - The Java Classpath Path is Incomplete. Only syntax errors will be reported.

I am taking the first steps with java, after several extensive experiences with python. script I am running a simple Java Swing Gui that compiles and works fine from the command line and in VS Code.

To set up the java debugging environment, I used the lauch.json settings suggested on the github site https://github.com/k--kato/vscode-javadebug .

Unfortunately, every time I open the folder containing the script, the following error message appears:

Warn: Classpath is incomplete. Only syntax errors will be reported. 

I have no idea if the problem arises from the VS code, if it is some other configuration problem, for example, setting up java ....

My working platform is Linux Ubuntu, Gnome Shell.

Can anyone help?

This is the script:

 //file name = SimpleEx.java import java.awt.EventQueue; import javax.swing.JFrame; public class SimpleEx extends JFrame { public SimpleEx() { initUI(); } private void initUI() { setTitle("Simple example"); setSize(300, 200); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args) { EventQueue.invokeLater(() -> { SimpleEx ex = new SimpleEx(); ex.setVisible(true); }); } } 

and this is my launch.json:

 { "version": "0.2.0", "configurations": [ { "name": "Java", "type": "java", "request": "launch", "stopOnEntry": true, "cwd": "${fileDirname}", "startupClass": "${fileBasename}", "options": [ "-classpath", "${fileDirname}" ] }, { "name": "Java Console App", "type": "java", "request": "launch", "stopOnEntry": true, "cwd": "${fileDirname}", "startupClass": "${fileBasename}", "options": [ "-classpath", "${fileDirname}" ], "externalConsole": true } ] } 
+17
source share
5 answers

This warning is displayed when opening a java file that the redhat.java extension cannot determine the class path. To get the full benefits of the extension, use either a project with maven pom.xml (soon also gradle), or minimal eclipse default configuration files, as well as .classpath.project files.

+9
source

I know this is an old question, but anyone who stumbles here and needs a quick and easy solution can find it here. Install the extension: Eclipse New Java Project .

It emulates the behavior of an Eclipse action when creating a Java Project and should produce the results you need.

Just press Ctrl + Shift + P and enter New Java Project (it will appear after a few letters) and follow simple instructions. (he just asks for the name of the project).

It will create the necessary project and files, and you do not have to worry about this classpath error. Then simply create the class files as usual in the src folder of your new project and start programming!

+7
source

As the Microsoft Visual Studio code ecosystem is rapidly evolving for Java, there is a convenient solution that helps tremendously - in just a few steps - create a working Java project structure for use with VS Code.

Of course, there are other solutions for working with Java, such as NetBeans, but I always really liked VS Code, and I just waited for something simpler to come back to use it.

A fairly simple solution that I found is to use MAVEN. Maven creates the entire project structure and configuration source files in your home folder, and you can immediately open it with VS Code and run it without any hassle.

Of course, you will need to install Java extensions as described here .

The solution I found here on the web was a bit dated, so I made some changes.

This is the process on a Linux computer:

  1. Check if you have MAVEN installed

    • Enter in the terminal:

       mvn --version 
    • If maven is not installed, the installation command will be displayed in the output;

  2. Call the maven quick launch archetype to create your new project;

    • Inside the terminal, enter or copy:

       mvn archetype:generate 
    • This will open up a scary list of over 2,000 types to choose from. The good news is that if you do not enter a number, maven-archetype-quickstart will be automatically selected, so just press ENTER.

    • Select a version from the list and enter the number: I selected the proposed number = 6

    • Select a value for the groupId property:

       com.mycompany.app 
    • Define the value for the 'artifactId' property (this will create a folder in your home directory):

       my-app 
    • Define value for 'version': 1.0

    • Define the value for the 'package' property:

       com.mycompany.app 
    • Confirm the settings and the project will be created.

  3. Launch VS Code with a new project

    • In the terminal, enter:

       code ./my-app 
  4. Customize Launch.json File

    • In the upper left corner of the debugger, to the right of the green color, where it says "no configuration", select "Java" from the drop-down field, and the .json file will be created automatically.
  5. Configure Task.json

    • Go to Task in the menu bar;
    • Customize Tasks ......
    • Create task.json from the template ....
    • Select "maven" from the drop-down list and the .json file will be created automatically.

You are good to go.

+5
source

Looking for this, I found that vscode now only recognizes maven projects or eclipse projects, so it needs a .classpath file. Therefore, the best option is to create a project with maven first and then open with vscode.

+3
source

The workaround for everyday work is complicated. I ended up with Intellij CE

0
source

Source: https://habr.com/ru/post/1012689/


All Articles