2

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.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.

6
  • Any reason you're not using an IDE (Eclipse, IntelliJ IDEA, NetBeans, ...)? Commented Jun 29, 2011 at 20:17
  • 1
    @Matt - any reason why he should? Commented Jun 29, 2011 at 20:26
  • @Kevin stackoverflow.com/questions/208193/why-should-i-use-an-ide Commented Jun 29, 2011 at 20:29
  • @Matt - disagree - for this simple stuff an IDE gets in the way. Understanding the API and how to use vi/emacs/xxx will save you some day. That said, my 'big' dev work gets done in an IDE, but I still do plenty of work using a plain old text editor. Commented Jun 29, 2011 at 20:32
  • Two reasons, really both the same. Commented Jun 29, 2011 at 20:43

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 This is the right way to do it. (You could ommit the -classpath ., as this is the default if not given.)
0

javac *.java


Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.