我有一个没有 main 方法的代码。该项目是使用以下命令执行的:
$mvn clean install -Dparam1="folder" -Dparam2="path"
在 Eclipse 或 IntelliJ 中,我只需要创建一个 maven 执行器,将 goas 定义为 clean install
并使用 -Dparam
传递 Maven 参数格式。
在 VSCode 中,我看到了 3 种不同的方法并尝试了以下方法:
- 创建
lunch.json
文件调用命令mvn
或mvnDebug
在preLaunchTask
.
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"request": "launch",
...
"preLaunchTask": "mvnDebug",
"vmArgs": [ "clean", "install", "-Dparam1=\"blabla\"", "-Dparam2=\"blablabla\"" ]
}
]
}
我还测试了通过 preLaunchTask
中的所有命令没有 vmArgs
.并没有奏效。
- 创建
task.json
传递脚本和launch.json
的文件将调用preLaunchTask
的文件使用参数taskName
中定义的名称创建的任务的task.json
.
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"request": "launch",
"preLaunchTask": "Debug",
"name": "Launch Program",
"sourceMaps": true
}
]
还有 tasks.json
:
{
"version": "2.0.0",
"tasks": [
{
"label": "Debug",
"type": "java",
"script": "mvnDebug clean install -Dparam1=\"folderName\" -Dparam2=\"blablabla\"",
"problemMatcher": []
}
]
}
- 我尝试过的第三种方法是使用
settings.json
:
{
"maven.terminal.favorites": [
{
"alias": "CLEAN COMPILE",
"command": "clean install -Dparam1=\"value\" -Dparam2=\"blabla\"",
"debug": true
},
]
}
对于所有这些,我都在终端中收到了消息:
Listening for transport dt_socket at address: 56787
伙计们,我需要你们做的是:
- 这条消息是什么意思?
- 为什么要等待端口?
- VSCode 是如何使用套接字来做到这一点的?
- 什么是最好的方法,为什么?
- 最重要的一点:如何使用 VSCode 在没有主要功能代码的情况下运行参数化的 JAVA MAVEN?
观察:我的 JAVA 版本是 JDK11,但我也尝试过使用 JDK 8。
非常感谢。
最佳答案
1.在launch.json
中,属性vmArgs
为
The extra options and system properties for the JVM (for example -Xms -Xmx -D=), it accepts a string or an array of string. debugging-launch
所以它不适用于您的应用程序。
2.在tasks.json
中,属性command
为要执行的命令;
3.建议使用设置maven.executable.options
, 它指定所有 mvn 命令的默认选项。
关于java - 如何配置 VSCode 带参数运行 Java MAVEN 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64393921/