Reputation: 304662
I have a simple Hello World program that works properly when run from within Eclipse. What do I need to do to run this program from the command line?
~/g/private/eclipse/Hello/bin --> java Hello.class
Error: Could not find or load main class Hello.class
Here are the eclipse-generated files:
~/g/private/eclipse/Hello --> find . -type f
./.classpath
./.gitignore
./.project
./.settings/org.eclipse.jdt.core.prefs
./bin/Hello.class
./src/Hello.java
and the eclipse-generated .classpath
:
~/g/private/eclipse/Hello --> cat .classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
(note) I don't think this is a dupe of this question, as I'm explicitly asking about running a program compiled in eclipse. How to run Java program in command prompt
Upvotes: 0
Views: 99
Reputation: 68715
no need to give .class
~/g/private/eclipse/Hello/bin --> java Hello.class
just run like
~/g/private/eclipse/Hello/bin --> java Hello
or, specifying the class path:
~/g/private/eclipse/Hello java -cp bin Hello
Upvotes: 1
Reputation: 26077
java.exe
or java
expects a class name as its argument, not a file name
java -classpath C:\user\ Hello
So running java Hello.class
will tell it to go looking for hello.class.class
file.
or define classpath and use
java -cp C:\user\ Hello
PS : From Stackoverflow source
Upvotes: 2