简体   繁体   English

IntelliJ:无法使用命令行启动 java 应用程序

[英]IntelliJ: cannot launch a java application using the command line

Let me summarize the problem:让我总结一下问题:

  • An exercise asked me to launch a java application using the Windows 10 Command Line.一个练习要求我使用 Windows 10 命令行启动 java 应用程序。
  • It taught me on a video how to add the IntelliJ path to the Environment Variables, so that, whenever I typed java Main I would get my Main.java/class application back.它在视频中教我如何将 IntelliJ 路径添加到环境变量中,这样,每当我键入java Main时,我都会恢复我的Main.java/class应用程序。
  • The first problem that I had stumbled upon was that, instead of using java Main , I'd have to type java Main.java .我偶然发现的第一个问题是,我必须输入java Main.java而不是使用java Main I thought that it was due to a recent build for the JDK (v14.02), so I let that one pass.我认为这是由于最近为 JDK(v14.02)构建的,所以我让它通过了。
  • The second problem that I had encountered was that, when the exercise asked me to launch an application using the package directories, the command line would return the following error: Error: Could not find or load main class com.pluralsight.organized.Main. Caused by: java.lang.ClassNotFoundException: com.pluralsight.organized.Main我遇到的第二个问题是,当练习要求我使用 package 目录启动应用程序时,命令行将返回以下错误: Error: Could not find or load main class com.pluralsight.organized.Main. Caused by: java.lang.ClassNotFoundException: com.pluralsight.organized.Main Error: Could not find or load main class com.pluralsight.organized.Main. Caused by: java.lang.ClassNotFoundException: com.pluralsight.organized.Main . Error: Could not find or load main class com.pluralsight.organized.Main. Caused by: java.lang.ClassNotFoundException: com.pluralsight.organized.Main
  1. Revert whatever damage you've done to the system.恢复您对系统造成的任何损害。
  2. Install the Oracle JDK.安装 Oracle JDK。
  3. Put the Oracle JDK bin folder on your PATH variable.将 Oracle JDK bin 文件夹放在 PATH 变量中。
  4. Compile your code using javac Main.java使用 javac Main.java 编译您的代码
  5. Run your compiled code using java Main使用 java Main 运行编译的代码
  6. for the ones in the packages, you need to be at the package root, or have a class path to it.对于包中的那些,您需要位于 package 根目录,或者拥有 class 路径。 For example, let's consider a class com.example.Main例如,让我们考虑一个 class com.example.Main

The folder structure should be: D:/SomePath/com/example/Main.class Then you need to be at D:/SomePath/ to execute java com.example.Main .文件夹结构应该是: D:/SomePath/com/example/Main.class然后你需要在D:/SomePath/执行java com.example.Main Alternatively, you could be anywhere else and execute java -cp D:/SomePath com.example.Main .或者,您可以在其他任何地方执行java -cp D:/SomePath com.example.Main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM