Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task command using wildcards in arg in Visual Studio Code

I am using Visual Studio Code 0.9.2 on OS X Yosemite to edit a .java file.

I attempt to compile this file using the following tasks.json file:

{
    "version": "0.1.0",
    "command": "javac",
    "isShellCommand": true,
    "echoCommand": true,
    "showOutput": "always",
    "args": ["-d","${workspaceRoot}\/target","${workspaceRoot}\/src\/*.java"]
}

Executing this task echoes the following command to the Output window:

running command$ javac -d /Users/caoimheboers/Desktop/JLab11/target
/Users/caoimheboers/Desktop/JLab11/src/*.java

... which is fine, however the result of the task execution is then reported as:

javac: file not found: /Users/caoimheboers/Desktop/JLab11/src/*.java
Usage: javac <options> <source files>
use -help for a list of possible options

I have tried the following:

  1. Copy the echoed javac command (including all arguments) from the Output window and paste it to the command line in a Terminal window. Result: The single .java file in the /src folder compiles and a .class file appears in the /target folder. This indicates that the syntax of the javac command (including all arguments) is correct in the tasks.json file.

  2. In the tasks.json file, replace the wildcard character with the name of the single .java file in the /src folder. Result: The VS Code task runs perfectly, and produces a .class file in the /target folder. This indicates that everything about the command in the tasks.jason file is OK except for the wildcard character.

Any ideas on what I'm doing wrong?

like image 514
Martin Avatar asked Nov 13 '15 17:11

Martin


People also ask

How do I run a task in VS Code?

Task auto-detection Below is an example of the tasks detected for the vscode-node-debug extension. Tip: You can run your task through Quick Open (Ctrl+P) by typing 'task', Space and the command name.

What is problemMatcher in VS Code?

The problem matcher to be used if a global command is executed (e.g. no tasks are defined). A tasks. json file can either contain a global problemMatcher property or a tasks property but not both.

What is workspaceFolder in VS Code?

${workspaceFolder} - the path of the folder opened in VS Code. ${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)

Where Is tasks json in VS Code?

You need to configure the tasks in a tasks. json file (located under your workspace . vscode folder) if you want to do more than simply run the task.


1 Answers

I also experienced it, it was apparently a bug. Currently there is a new terminal runner which fixes this error. Try to change the tasks JSON schema to new 2.0.0 version, reload the window and everything will be fine:

{
    "version": "2.0.0",
    "command": "javac",
    "isShellCommand": true,
    "echoCommand": true,
    "showOutput": "always",
    "args": ["-d","${workspaceRoot}/target","${workspaceRoot}/src/*.java"]
}

The related issue is here: https://github.com/Microsoft/vscode/issues/16865

You don't need to escape the slash character by the way.

like image 129
Adam Szlachta Avatar answered Nov 10 '22 20:11

Adam Szlachta