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

huangapple go评论101阅读模式
英文:

IntelliJ: cannot launch a java application using the command line

问题

让我总结一下这个问题:

  • 一道练习要求我使用Windows 10命令行来启动一个Java应用程序。
  • 它在一个视频中教我如何将IntelliJ的路径添加到环境变量中,这样,无论我键入java Main,都会得到我的Main.java/class应用程序。
  • 我遇到的第一个问题是,我不是要使用java Main,而是必须键入java Main.java。我以为这是由于JDK的最新版本(v14.02)的构建问题,所以我就放过了这个问题。
  • 我遇到的第二个问题是,当练习要求我使用包目录启动应用程序时,命令行会返回以下错误:Error: Could not find or load main class com.pluralsight.organized.Main。 Caused by: java.lang.ClassNotFoundException: com.pluralsight.organized.Main
英文:

Let me summarize the problem:

  • An exercise asked me to launch a java application using the Windows 10 Command Line.
  • 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.
  • The first problem that I had stumbled upon was that, instead of using java Main, I'd have to type java Main.java. I thought that it was due to a recent build for the JDK (v14.02), so I let that one pass.
  • 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.

答案1

得分: 2

  1. 恢复您对系统所做的任何损坏。
  2. 安装 Oracle JDK。
  3. 将 Oracle JDK 的 bin 文件夹添加到您的 PATH 变量中。
  4. 使用 javac Main.java 编译您的代码。
  5. 使用 java Main 运行您编译的代码。
  6. 对于包中的类,您需要在包的根目录,或者具有类路径。例如,让我们考虑一个类 com.example.Main。

文件夹结构应为:
D:/SomePath/com/example/Main.class
然后您需要在 D:/SomePath/ 执行 java com.example.Main
或者,您也可以在任何其他位置执行 java -cp D:/SomePath com.example.Main

英文:
  1. Revert whatever damage you've done to the system.
  2. Install the Oracle JDK.
  3. Put the Oracle JDK bin folder on your PATH variable.
  4. Compile your code using javac Main.java
  5. Run your compiled code using java Main
  6. for the ones in the packages, you need to be at the package root, or have a class path to it. For example, let's consider a 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.
Alternatively, you could be anywhere else and execute java -cp D:/SomePath com.example.Main.

huangapple
  • 本文由 发表于 2020年8月19日 03:11:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63475207.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定