Cannot run Java from the Windows PowerShell command prompt

前端 未结 9 883
野性不改
野性不改 2020-12-16 16:55

I have Java installed on my machine (the JRE is under C:\\Program Files\\Java) but I can\'t run any java command from the Windows PowerShell command prompt.

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 17:52

    If the environment variable is set or you have sourced the environment appropriately, the issue is executing a file in a shell:

    javac .\HelloWorld.java      //That is a file, so it can be ./
    
    java HelloWorld              //Not the correct file name, so it will not execute, and so must call it as in MSDOS
    

    You cannot .\ on the HelloWorld.class as the Java bytecode must be executed without the extension, .\ is for file execution.

提交回复
热议问题