Search code examples
jarcommandlinekarateargs

Karate Runner -> karate jar : Command line args settings issue


I am using Visual Studio code and Karate Runner plugin is installed. Using karate-config.js with standalone jar (karate.jar). I have tried to configure in karate runner settings in VS code for Karate Runner -> karate jar : Command line args as "java -Dkarate.config.dir=test/resources/ -cp karate.jar com.intuit.karate.Main" but it throws an exception like

Executing task: java -Dkarate.config.dir=test/resources/ -cp karate.jar com.intuit.karate.Main "d:\GitHub\KarateTestFramework\test\features\script\all_users.feature:9" <

Error: Could not find or load main class .config.dir=test.resources. The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command java -Dkarate.config.dir=test/resources/ -cp karate.jar com.intuit.karate.Main "d:\GitHub\KarateTestFramework\test\features\script\all_users.feature:9"" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Also, I have tried full path for -Dkarate.config.dir=D:/GitHub/KarateTestFramework/test/resources but didn't work either.

Please guide me to resolve this issue.


Solution

  • @ChandramohanRamabadran, I tried to replicate the issue on my system. I believe it's not a bug!

    It's happening because your VisualStudio is using PowerShell instead of CMD. I believe you might have missed the step to change the default shell of VisualStudio after installing Karate. Try updating the default shell from PowerShell to CMD; then you should be good.

    However, if you still want to use PowerShell, then update the command

    java -Dkarate.config.dir=test/resources/ -cp karate.jar com.intuit.karate.Main
    

    to

    java `-Dkarate.config.dir`=test/resources/ -cp karate.jar com.intuit.karate.Main
    

    More context over the issue: PowerShell has a more standard rule to parse system-properties parameters which are different from CMD. In a PowerShell command, the parameter names always begin with a hyphen. The hyphen tells PowerShell that the item in the command is a parameter name.

    Here, we are passing the parameter as -Dkarate.config.dir, PowerShell sights the parameter name-tag as -Dkarate and not -Dkarate.config.dir; hence the error.