javamakefilepackage

Makefile cannot find class in package


I am trying to create a makefile for my java program. The program compiles correctly in my IDE. Here is what my makefile looks like.

JAVAC=javac
sources = $(wildcard */*/*/*.java)
classes = $(sources:.java=.class)
all: $(classes)
clean :
    rm -f */*/*/*.class
%.class : %.java
    $(JAVAC) $<

When I run this, the first file it finds it compiles fine, but on the second one it fails. The first file happens to be an interface, and the second file is an implementation of that interface. This is the error message.

javac p1/p2/event/Event.java
javac p1/p2/event/RegisterEvent.java
p1/p2/event/RegisterEvent.java:7: error: cannot find symbol
public class RegisterEvent implements p1.p2.event.Event {
                                                     ^
symbol:   class Event
location: package p1.p2.event
1 error
make: *** [p1/p2/event/RegisterEvent.class] Error 1

Why can it not find the class when I am compiling it?


Solution

  • You need to add the classpath to the javac command.

    Something like javac -cp . p1/p2/event/Event.java