英文:
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 myMain.java/class
application back. - The first problem that I had stumbled upon was that, instead of using
java Main
, I'd have to typejava 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
- 恢复您对系统所做的任何损坏。
- 安装 Oracle JDK。
- 将 Oracle JDK 的 bin 文件夹添加到您的 PATH 变量中。
- 使用 javac Main.java 编译您的代码。
- 使用 java Main 运行您编译的代码。
- 对于包中的类,您需要在包的根目录,或者具有类路径。例如,让我们考虑一个类 com.example.Main。
文件夹结构应为:
D:/SomePath/com/example/Main.class
然后您需要在 D:/SomePath/
执行 java com.example.Main
。
或者,您也可以在任何其他位置执行 java -cp D:/SomePath com.example.Main
。
英文:
- Revert whatever damage you've done to the system.
- Install the Oracle JDK.
- Put the Oracle JDK bin folder on your PATH variable.
- Compile your code using javac Main.java
- Run your compiled code using java Main
- 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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论