Running Java Program From Command Line(从命令行运行 Java 程序)
问题描述
所以我在这里有一个菜鸟时刻,我以前从未使用过命令行来运行 java 程序,但我现在需要.我遇到的问题是,当我尝试运行程序时,我得到了 ClassNotFoundException.我的课程叫做 OmadUpdate.我已经使用 javac 命令将 OmadUpdate.java 文件编译到 OmadUpdate.class 中.我检查了目录,它们肯定都在那里,但是当我运行 java OmadUpdate 命令时,它给了我一条错误消息,说
so I am having a noob moment here, I haven't ever used the command line to run a java program before but I need to right now. The problem I am having is that when I try to run the program I get a ClassNotFoundException. My class is called OmadUpdate. I already have compiled the OmadUpdate.java file into OmadUpdate.class using the javac command. I have checked the directory and they are both definitely there, however when I run the java OmadUpdate command, it gives me an error message saying
Exception in thread "main" java.lang.NoClassDefFoundError: OmadUpdate (wrong name: org/openmetadata/main/OmadUpdate)
......
......
Could not find the main class: OmadUpdate. Program will exit
但它就在目录中.当我键入 dir 时,我同时拥有 OmadUpdate.class 和 OmadUpdate.java.我什至尝试过使用java org.openmetadata.main.OmadUpdate",因为这是它所在的包名.我难住了.感谢您的帮助.
But its right there in the directory. When I type dir I have both OmadUpdate.class and OmadUpdate.java. I have even tried using "java org.openmetadata.main.OmadUpdate" because that is the package name that it is under. I am stumped. Thanks for the assistance.
推荐答案
您的类似乎已在 org.openmetadata.main
包中声明.
Your class appears to have been declared in the org.openmetadata.main
package.
要让java正确加载类,它需要位于与包结构匹配的正确目录结构中.
To get java to load the class correctly, it needs to be in the correct directory structure that matches the package structure.
所以 org.openmetadata.main.OmadUpdate
的类文件应该在目录 orgopenmetadatamain
中.
So the classfiles for org.openmetadata.main.OmadUpdate
should be in the directory orgopenmetadatamain
.
然后,当你运行 java
命令时,这个目录结构的根目录应该在类路径上 - 举个简单的例子,这只是意味着你的当前目录应该是 orgopenmetadatamain
.
Then, when you run the java
command, the root of this directory structure should be on the classpath - for a simple example this just means that your current directory should be the parent directory of orgopenmetadatamain
.
运行 java
时,您需要使用句点而不是斜杠指定完整的类名,即
When running java
you need to specify the full classname using periods not slashes, i.e.
java org.openmetadata.main.OmadUpdate
这篇关于从命令行运行 Java 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从命令行运行 Java 程序


- 转换 ldap 日期 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 获取数字的最后一位 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01