Skip to content

Instantly share code, notes, and snippets.

@callemo
Last active March 29, 2020 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callemo/49b84e81005645b5fad22c8ee00a7690 to your computer and use it in GitHub Desktop.
Save callemo/49b84e81005645b5fad22c8ee00a7690 to your computer and use it in GitHub Desktop.
Makefile for java projects
artifactId = a
directory = build
outputDirectory = $(directory)/classes/java/main
sourceDirectory = src/main/java
sources = $(shell find $(sourceDirectory) -name \*.java)
objects = $(sources:$(sourceDirectory)/%.java=$(outputDirectory)/%.class)
package = $(directory)/libs/$(artifactId).jar
JAR = jar
JAR_FLAGS = cvf
JAVA = java
JAVAC = javac
JAVAC_FLAGS = -g
COMPILE.java = $(JAVAC) -d $(outputDirectory) $(JAVAC_FLAGS)
.PHONY: all clean
all: $(package)
$(package): $(objects)
$(objects): $(outputDirectory)/%.class: $(sourceDirectory)/%.java
$(COMPILE.java) $<
%.jar:
mkdir -p `dirname $@`
$(JAR) $(JAR_FLAGS) $@ -C $(outputDirectory) $(^:$(outputDirectory)/%=%)
clean:
$(RM) -r $(directory)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment