I'm kinda new to compiling using cmd line javac and I'm having trouble compiling this simple Base-Interface class
package com.apress.prospring2.ch03.di;
/**
* @author janm
*/
public interface Encyclopedia {
Long findLong(String entry);
}
package com.apress.prospring2.ch03.di;
import java.util.Map;
import java.util.HashMap;
/**
* @author janm
*/
public class HardcodedEncyclopedia implements Encyclopedia {
private Map<String, Long> entryValues = new HashMap<String, Long>();
public HardcodedEncyclopedia() {
this.entryValues.put("AgeOfUniverse", 13700000000L);
this.entryValues.put("ConstantOfLife", 326190476L);
}
public Long findLong(String entry) {
return this.entryValues.get(entry);
}
}
I can easily compile Encyclopedia using javac Encyclopedia.java but when I try to compile HardcodedEncyclopedia .java I get
HardcodedEncyclopedi开发者_高级运维a.java:9: cannot find symbol
symbol: class Encyclopedia
public class HardcodedEncyclopedia implements Encyclopedia {
^
1 error
Can someone please tell me how to solve this without using Ant or Maven? Thanks :)
You need to compile you classes from the top level of your packages, so in this case, you need to be in the directory where the "com" sits.
Then you can do your compilation:
javac -cp . com/apress/prospring2/ch03/di/*.java
I suspect that you're trying to compile HardcodedEncyclopedia.java
from inside of the com/apress/prospring2/ch03/di
directory. Even though Encyclopedia.java
is in the same directory, javac needs to know how to find the om.apress.prospring2.ch03.di
package its expected to be in. You can either specify the classpath like this:
javac -cp ../../../../.. HardcodedEncyclopedia.java
Or you can go to the root directory to imply the classpath as the current directory, like this:
cd ../../../../..
javac com/apress/prospring2/ch03/di/HardcodedEncyclopedia.java
Try:
javac Bar.java Foo.java
This is considering they are in the same package
精彩评论