【问题标题】:How do I debug a spring mvc web app with web.xml on Visual Studio Code?如何在 Visual Studio Code 上使用 web.xml 调试 spring mvc Web 应用程序?
【发布时间】:2018-01-04 06:36:28
【问题描述】:

我正在使用 Visual Studio Code 开发一个带有 maven 构建工具的 spring mvc 应用程序。

我的系统上安装了 maven 命令行。我还在我的 pom.xml 中添加了 tomcat 插件。我的应用程序的入口点是 web.xml。

我创建了 vs code 任务来在集成终端上运行 maven 命令。

我应该如何附加调试器断点以通过程序运行检查变量值。

我的 task.json 看起来像这样:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "verify",
            "type": "shell",
            "command": "mvn -B verify",
            "group": "build"
        },
        {
            "label": "test",
            "type": "shell",
            "command": "mvn -B test",
            "group": "test"
        },
        {
            "label": "create a  new maven webapp",
            "type": "shell",
            "command": "mvn archetype:generate -DgroupId=com.lumen.app -DartifactId=lumen-app -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false",
            "group": "test"
        },
        {
            "label": "clean",
            "type": "shell",
            "command": "mvn clean",
            "group": "test"
        },
        {
            "label": "install",
            "type": "shell",
            "command": "mvn install",
            "group": "test"
        },
        {
            "label": "run on server",
            "type": "shell",
            "command": "mvn tomcat7:run",
            "group": "test"
        },
        {
            "label": "redeploy on server",
            "type": "shell",
            "command": "mvn tomcat7:redeploy",
            "group": "test"
        },
        {
            "label": "undeploy on server",
            "type": "shell",
            "command": "mvn tomcat7:undeploy",
            "group": "test"
        },
        {
            "label": "deploy on server",
            "type": "shell",
            "command": "mvn tomcat7:deploy",
            "group": "test"
        }
    ]
} 

【问题讨论】:

  • Visual Studio Code 基本上是一个美化的文本编辑器。 Sprint MVC 是,AFAIK,几乎完全是一个 Java(即“非微软”)环境。而且 Maven 主要是一个构建工具——我不确定你认为它与 Visual Studio Code 或 Spring MVC 调试有什么关系:(所以基本上——祝你好运!就个人而言,我建议尝试使用 Eclipse。它集成得很好与Tomcat,并提供了一个很好的交互式构建和调试环境。恕我直言...
  • 我创建了运行 maven 构建工具命令来编译项目、安装依赖项和运行应用程序的 vs code 任务。

标签: java spring maven spring-mvc visual-studio-code


【解决方案1】:

考虑到这些事实:- 1.应用是一个mvc webapp 2.调试器由VS Code提供

这是一个简单的两步过程,但您需要了解此设置的工作原理。

首先,配置一个任务,让您的应用在调试模式下运行。 其次,将 VS Code 调试器附加到调试模式监听和响应的端口。

调试模式允许任何调试器通过特定端口将自己附加到应用程序。

在您的 tasks.json 中配置如下任务:

{
        "label": "debug on server",
        "type": "shell",
        "command": "export MAVEN_OPTS='-Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000';mvn tomcat7:run",
        "group": "test"
}

这允许您的代码在调试模式下运行,然后将 VS Code 调试器附加到端口 8000。

要附加调试器,请将以下配置添加到 launch.json :

{
        "type": "java",
        "name": "Debug (Attach)",
        "request": "attach",
        "hostName": "localhost",
        "port": 8000
}

现在在服务器任务上运行调试后附加您的调试点。

【讨论】:

  • 这真的有效吗?它是在简单的 VS Code 上,还是您还下载了 VS Code 的相关 Spring Tools 扩展?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-27
  • 2018-12-02
  • 2022-07-22
  • 2016-10-12
  • 2021-06-23
  • 2016-04-01
  • 2019-04-19
相关资源
最近更新 更多