WizDom
WizDom

Reputation: 57

Executing make on the command line (Java)

I'm aware that Makefiles and Java probably don't play nice together, but say you have something simple like this as a Makefile:

    JAVAC=javac
    sources = $(wildcard *.java)
    classes = $(sources:.java=.class)

    all: $(classes)

    clean :
        rm -f *.class

    %.class : %.java
        $(JAVAC) $<

I want to create an executable by typing something like:

    make myProgram

but I get a message saying:

    "make: *** No rule to make target `myProgram'.  Stop."

I know "make" by itself will work, but that's not what I want.

Is what I want to do even possible with a .java files? If so, how can I modify the Makefile? Thanks for any input/suggestions.

Upvotes: 0

Views: 58

Answers (1)

rgettman
rgettman

Reputation: 178263

You don't have a myProgram target, so make complains.

You could make make myProgram and make work and do the same thing by defining a myProgram target, and defining all to be myProgram:

all: myProgram

myProgram: $(classes)

Upvotes: 3

Related Questions