Skip to content

Instantly share code, notes, and snippets.

@CorneilleEdi
Last active February 9, 2022 09:14
Show Gist options
  • Save CorneilleEdi/2125556867e7f268da0a75b7161b7895 to your computer and use it in GitHub Desktop.
Save CorneilleEdi/2125556867e7f268da0a75b7161b7895 to your computer and use it in GitHub Desktop.
Go to java Makefile
JAVAC=javac
JAVA=java
JAVADOC=javadoc
OUT_DIR=out
DOCS_DIR=docs
SRC_DIR=.
JAVA_FILES=$(notdir $(wildcard $(SRC_DIR)/*.java))
CLASS_FILES=$(JAVA_FILES:%.java=$(OUT_DIR)/%.class)
MAIN_CLASS=Main
all: dirs jar
jar: $(CLASS_FILES)
$(OUT_DIR)/%.class : $(SRC_DIR)/%.java
$(JAVAC) $< -d $(OUT_DIR) -classpath $(SRC_DIR)
# Can not run since we do not have a proper main.
# We have to run the server and then the Client.
run: all
$(JAVA) -server -XX:-AggressiveOpts -classpath $(OUT_DIR) $(MAIN_CLASS)
.PHONY: dirs clean
dirs: $(OUT_DIR)
doc :
mkdir -p $(DOCS_DIR) && $(JAVADOC) $(JAVA_FILES) -d $(DOCS_DIR)
$(OUT_DIR):
mkdir -p $@
$(DOCS_DIR):
mkdir -p $@
clean :
rm -rf $(DOCS_DIR)
rm -rf $(OUT_DIR)
@CorneilleEdi
Copy link
Author

My go-to java Makefile when I'm not working with an IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment