Makefile to compile and run Java sources manually
December 8, 2022 · View on GitHub
because JDK 20 Valhalla support is not yet available in IntelliJ IDEA
JAVA_VERSION = 20 JAVAC = /home/user/downloads/jdk-20-vahalla-20-75/bin/javac JAVA = /home/user/downloads/jdk-20-vahalla-20-75/bin/java
JAVA_COMPILE_OPTIONS = --enable-preview --release $(JAVA_VERSION) JAVA_OPTIONS = --enable-preview
JAVA_MAIN_CLASS = org.example.Database JAVA_SOURCES = (patsubst src/main/java/%.java, target/classes/%.class, $(JAVA_SOURCES))
Compile the Java source files
compile: (info Java source files: (info Java class files: $(JAVA_CLASSES))
Run the Java main class
run: compile (JAVA_OPTIONS) -cp target/classes $(JAVA_MAIN_CLASS)
Clean the target directory
clean: rm -rf target
Compile the Java source files
target/classes/%.class: src/main/java/%.java (JAVA_COMPILE_OPTIONS) -d target/classes $<
Create the target directory
target/classes: mkdir -p target/classes
Make the target directory a dependency of the Java class files
$(JAVA_CLASSES): target/classes
Make the target directory a dependency of the compile target
compile: target/classes
Ditto...
clean: target/classes run: target/classes default: target/classes
default: run