Visual Studio代码 - Java类路径不完整。仅报告语法错误 [英] Visual Studio Code - Java Classpath is incomplete. Only syntax errors will be reported

查看:1536
本文介绍了Visual Studio代码 - Java类路径不完整。仅报告语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用python的一些丰富经验之后,我正在使用java开始我的第一步。我运行的脚本是一个简单的Java Swing Gui,它可以从命令行和VS Code中编译和运行。

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 command line and within VS Code.

要设置java调试环境,我使用了github网站上建议的lauch.json设置 https://github.com/k--kato/vscode-javadebug

To set up the java debug 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 that contains the script, I get the following error message:

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

我不知道问题是否来自VS Code,如果是其他配置问题,比如java设置....

I have no idea if the problem comes from within VS Code, of if it's some other configuration issue, such as the java set up....

我的工作平台是Linux Ubuntu,Gnome Shell。

My working platform is Linux Ubuntu, Gnome Shell.

有人可以帮忙吗?

这是脚本:

//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);
        });
    }
}

这是我的launch.json:

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
        }
    ]
}


推荐答案

这当您打开 redhat.java 扩展无法扩展的java文件时,会显示警告确定一个类路径。要获得扩展的全部好处,请使用带有maven pom.xml的项目(很快也是gradle),或者使用最少的默认eclipse设置文件(即 .classpath .project 文件。

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.

这篇关于Visual Studio代码 - Java类路径不完整。仅报告语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆