Visual Studio Code - Java Classpath is incomplete. Only syntax errors will be reported

后端 未结 6 656
别跟我提以往
别跟我提以往 2021-01-31 18:52

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

相关标签:
6条回答
  • 2021-01-31 19:03

    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.

    0 讨论(0)
  • 2021-01-31 19:16

    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:

    1. Check if you have MAVEN installed

      • Type into a terminal:

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

    2. 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.

    3. Start VS Code with the new project

      • In the terminal type :

        code ./my-app 
        
    4. Configure a Launch.json file

      • In the top left of the debugger, on the right side of the green, where it says "no configuration", choose "Java" from the drop-down field and the .json file will be auto-generated.
    5. Configure a Task.json

      • Go to Task in the menu bar;
      • Configure tasks ......
      • Create task.json from template ....
      • Select "maven" from the drop-down list and the .json file will be auto-generated.

    You are good to go.

    0 讨论(0)
  • 2021-01-31 19:18

    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!

    0 讨论(0)
  • 2021-01-31 19:18

    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.

    0 讨论(0)
  • 2021-01-31 19:22

    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.

    0 讨论(0)
  • 2021-01-31 19:22

    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

    0 讨论(0)
提交回复
热议问题