4

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

HardcodedEncyclopedia.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 :)

0

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

1

Try:

javac Bar.java Foo.java

This is considering they are in the same package

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.