I installed Java on Windows 10. It installed here: C:\\Program Files\\Java\\jdk-10.0.1
. I made sure the path had been modified to include the bin
folder and java.exe
. I can type 'java' in a cmd window and get the java usage message. So, that works.
Then I installed Eclipse. I went through the tutorial section walkthru to create the HelloWorld
program. And it runs in Eclipse. Here it is:
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World!");
}
}
Now that I have that set up correctly, I wanted to try running it without Eclipse. So, I copied the HelloWorld.java
source file from the Eclipse work space to a folder I created under Documents, C:\\Users\\kris4\\Documents\\java
.
I open a cmd window, cd to C:\\Users\\kris4\\Documents\\java
, and do a dir
:
Volume in drive C has no label.
Volume Serial Number is A656-1FA0
Directory of C:\Users\kris4\Documents\java
05/24/2018 03:22 PM <DIR> .
05/24/2018 03:22 PM <DIR> ..
05/24/2018 11:20 AM 160 HelloWorld.java
1 File(s) 160 bytes
2 Dir(s) 116,141,473,792 bytes free
There it is...
But, when I execute, java HelloWorld.java
I get this:
Error: Could not find or load main class HelloWorld.java
Caused by: java.lang.ClassNotFoundException: HelloWorld.java
The file is right there in the working directory, and the file is a copy of a working Eclipse workspace file. WTH! Looking on the internet, I thought java needs CLASSPATH
to find the source, so I defined a variable CLASSPATH
to be the directory HelloWorld.java
resides in. Still no luck.
Obviously, being new to this, I'm missing something very basic in the cmdline environment that should be there, but I honestly expected java.exe
to look in the current working directory for a file given as an argument, like any other program.
Can one of you folks help me out?
Use:
javac HelloWorld.java
not just
java HelloWorld.java
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.