简体   繁体   English

Java在Eclipse中运行良好,但无法在终端中正常运行

[英]Java works fine in Eclipse, but cannot run normally in Terminal

Environment: Ubuntu 12.04, JRE 1.6.0 环境:Ubuntu 12.04,JRE 1.6.0

In my zsh, even a simple hello.java cannot run normally. 在我的zsh中,即使是简单的hello.java也无法正常运行。 It's ok when compiled it with javac , but then typed java hello : javac编译可以,但是键入java hello

Exception in thread "main" java.lang.NoClassDefFoundError: hello
Caused by: java.lang.ClassNotFoundException: hello
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: hello.  Program will exit.

Your class name seems to be helloworld and you are trying to say java hello 您的班级名称似乎是helloworld并且您正在尝试说java hello

(hence JVM tries to find a class named hello which doesnt exist) (因此,JVM试图找到一个不存在的名为hello的类)

please try java -classpath . helloworld 请尝试java -classpath . helloworld java -classpath . helloworld

The class name is helloworld and you are trying to say java hello . 该类的名称是helloworld ,您正在尝试说java hello Check it once 检查一次

Try java helloworld. 试试java helloworld。 By default, Java will compile with the same name as the file. 默认情况下,Java将使用与文件相同的名称进行编译。

so javac helloworld.java outputs helloworld.class, which is what you need to access to run the bytecode. 因此javac helloworld.java输出helloworld.class,这是运行字节码所需的访问权限。

暂无
暂无

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

相关问题 Java Applet在Eclipse中工作正常,但在终端机(Appletviewer)中不正确 - Java Applet works fine in Eclipse but in terminal(Appletviewer) not correctly 代码在调试模式下可以正常运行,但是在正常运行时(Eclipse)会停止 - Code running fine in debug mode, but stops when run normally (eclipse) Java终端失败,eclipse正常运行 - Java terminal fails, eclipse works 我的带有utf8的应用程序在Eclipse中可以正常工作,但在终端中却无法 - My app with utf8 works fine in eclipse but it doesn't in terminal 如何从命令行运行 java 项目(在 eclipse 中正常工作,gradle) - How to run java project from command line (works fine in eclipse, gradle) Java简单网络程序可在Eclipse中运行,而不是在终端中运行 - Java simple networking program works in Eclipse, not in terminal 除了这个命令(合并)之外,ffmpeg大部分时间在java中工作正常,这个命令在终端中工作正常 - ffmpeg works fine most of the time in java except for this command (merging), and this command works fine directly in terminal 我有不同版本的javac和java。 我正在尝试在终端上运行.java文件。 但是它可以在日食中工作 - I have different versions of javac and java. I'm trying to run my .java file on terminal. But it works in eclipse 无法在Eclipse中调试Mockito / JUnit代码,仅与JUnit一起工作即可 - Cannot debug Mockito / JUnit code in Eclipse, works fine with just JUnit Java setShape()方法在命令提示符下给出错误,但在Eclipse上工作正常 - Java setShape() method giving error on command prompt but works fine on eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM