DEV Community

Akhyar Amarullah
Akhyar Amarullah

Posted on • Originally published at akhy.chickenzord.com on

Minimal Makefile to Run Java Projects

Recently, a conversation with my SO reminded me about a piece of code I write long time ago. It was a college assignment on Data Structure course.

I immediately dug my email and found the project compressed in a RAR archive. The project was written using Java with NetBeans IDE default folder structure. There was no build configurtions like Maven, Ant, Makefile, or whatsoever. Only NetBeans project config and I don’t want to install it just for the sake of running the code.

After Googled a bit, I came with a quick and simple Makefile to run the code. Luckily there was no external dependencies to deal with.

SRC ?= src
DST ?= build/classes
MAIN ?= Main

.PHONY: clean compile run

clean:
    rm -f $$(find $(DST) -name *.class)

compile:
    mkdir -p $(DST)
    javac -d $(DST) $$(find $(SRC) -name *.java)

run:
    java -cp $(DST) $(MAIN)

Top comments (0)