java compile issue. Probably simple
It's been quite a while since I've used java extensively, and I'm having trouble with something I think is probably quite simple. Code is on a linux system, and I'm using javac and other command line tools.
Two files, the second won't compile. Here's the first, named ITranslator.java:
package org.helloopensource.greetings; public interface ITranslator { public abstract String translate(String fromLanguage, String toLanguage, String word); }
Here's the second, named Greeting.java:
package org.helloopensource.greetings; public class Greeting { private ITranslator translator; public Greeting(ITranslator translator) { this.translator = translator; } public String sayHello(String language, String name) { return translator.translate("English", language, "Hello") + " " + name; } }
When I try to compile, I get:
> javac -classpath `pwd` Greeting.java Greeting.java:4: cannot find symbol symbol : class ITranslator location: class org.helloopensource.greetings.Greeting private ITranslator translator; ^ Greeting.开发者_Python百科java:6: cannot find symbol symbol : class ITranslator location: class org.helloopensource.greetings.Greeting public Greeting(ITranslator translator) { ^ 2 errors
Like I said, I suspect this is something simple, or something dumb I'm doing wrong. Any help would be greatly appreciated.
Thanks,
Sean.
Java requires that class files be found in a subdirectory that matches their package names. So:
mkdir -p org/helloopensource/greetings mv *.java org/helloopensource/greetings/ javac -classpath . org/helloopensource/greetings/*.java
should do it.
javac *.java
精彩评论