I'm trying to wean myself from IDEs -- getting to be lazy as a programmer. Before posting, I looked at these sites and it didn't help:
Error compiling Java from command line Compiling java from the command line Javac "cannot find symbol" http://www.javaprogrammingforums.com/java-ides/16906-trouble-running-java-file-windows-command-prompt.html#post71916
I have the following path to my source files:
D:\workspace\HelloWorld\src\com\dogzilla
There are two files in that path: Start.java...
package com.dogzilla;
public class Start{
public Start() {
}
private static final String S = "Hello World";
public static void main(String[] args) {
HelloWorld hw = new HelloWorld();
hw.printHelloWorld(S);
}
}
...and HelloWorld.java
package com.dogzilla;
public class HelloWorld {
public HelloWorld() {
}
public void printHelloWorld(String s){
System.out.println(s);
}
}
When I change the directory to D:\workspace\HelloWorld\com\dogzilla\src\main\java
and run javac Start.java
, it errors with:
Start.java:14: error: cannot find symbol
HelloWorld hw = new HelloWorld();
^
symbol: class HelloWorld
location: class Start
Start.java:14: error: cannot find symbol
HelloWorld hw = new HelloWorld();
^
symbol: class HelloWorld
location: class Start
2 errors
So I've read you have to specify the classpath because of the package com.dogzilla;
line.
So I change the directory to D:\workspace\HelloWorld
and run javac -cp com\dogzilla\src\main\java\Start.java
(interestingly enough, the tab key completes the path so I know the command prompt is finding Start.java just fine) it errors with:
javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options
How can I compile and run this otherwise simple program? The IDE hides this otherwise and I'm having problems learning it.