'VSCode Java Project - java.lang.ClassNotFoundException if I run the project at other drive except in Windows drive (Drive C)

I like to organize the code in other drive except Windows drive in case of Windows reinstallation. I test in both location. In Windows drive, the project can run properly, but in the other hand, project that in the drive D cannot run because it caused the error java.lang.ClassNotFoundException. I notice that if I no have any library in the project, the command in terminal is '-cp' 'D:\งาน\Java\Project\MyApp\bin' 'com.winrecker.app.App". So the project can run properly without any error. After that, I copied the .jar library into lib folder and run again, the project has the same error as mentioned above. Is there any way that I can disable vscode for making the .argfile that caused the error? I'm tried to created .launch.json in .vscode folder. Then add a configuration as follows

launch.json

{
  "configurations": [
    {
      "type": "java",
      "name": "Launch Game",
      "request": "launch",
      "mainClass": "com.untitled.game.Game",
      "projectName": "Alien Hunter",
      "vmArgs": "-Djava.library.path=lib/lwjgl/native/windows",
      "shortenCommandLine": "none"
    }
  ]
}

settings.json

{
    "java.project.sourcePaths": [
        "src",
        "lib",
        "res"
    ],
    "java.project.outputPath": "bin",
    "java.project.referencedLibraries": [
        "lib/**/*.jar"
    ]
}

And run again, the project can at any drive other than Windows drive. I'm so curious why shortenCommandLine and create the .argfile caused the error in project that not in Windows drive.

Any help is appreciated.



Solution 1:[1]

The official docs said:

shortenCommandLine - When the project has long classpath or big VM arguments, the command line to launch the program may exceed the maximum command line string limitation allowed by the OS. This configuration item provides multiple approaches to shorten the command line. Defaults to auto.

  • none - Launch the program with the standard command line 'java options classname [args]'.
  • jarmanifest - Generate the classpath parameters to a temporary classpath.jar file, and launch the program with the command line 'java -cp classpath.jar classname [args]'.
  • argfile - Generate the classpath parameters to a temporary argument file, and launch the program with the command line 'java @argfile[args]'. This value only applies to Java 9 and higher.
  • auto - Automatically detect the command line length and determine whether to shorten the command line via an appropriate approach.

Looks like the path of the folder in the D driver is longer then in the C Driver, so the Java extension automatically creates the .argfile file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven-MSFT