我有一个 java 项目,需要编写 makefile 让它在 Linux 上运行。我的项目包括外部jar文件和资源包(.txt资源)。我真的是Linux新手,只是学习如何编写makefile。
我参考了一些材料并编写了这样的makefile:
# Set the file name of your jar package:
JAR_PKG = ADBproject1.jar
# Set your entry point of your java app:
ENTRY_POINT = adb/Bing_WebResults/Run.java
# Need resource directory
RES_DIR = yes
SOURCE_FILES = \
adb/jsonModels/Metadata.java \
adb/jsonModels/Result.java \
adb/jsonModels/Data.java \
adb/jsonModels/DataContainer.java \
adb/models/Weight_ID.java \
adb/models/Pair.java \
adb/models/Document.java \
adb/models/Collections.java \
adb/Bing_WebResults/Bing_Search.java\
adb/Bing_WebResults/Run.java \
JAVAC = javac
JFLAGS = -encoding UTF-8
vpath %.class bin
vpath %.java src
# show help message by default
Default:
@echo "make new: new project, create src, bin, res dirs."
@echo "make build: build project."
@echo "make clean: clear classes generated."
@echo "make rebuild: rebuild project."
@echo "make run: run your app."
@echo "make jar: package your project into a executable jar."
build: $(SOURCE_FILES:.java=.class)
# pattern rule
%.class: %.java
$(JAVAC) -cp bin -d bin $(JFLAGS) $<
rebuild: clean build
.PHONY: new clean run jar
new:
ifeq ($(RES_DIR),yes)
mkdir -pv src bin res
else
mkdir -pv src bin
endif
clean:
rm -frv bin/*
run:
java -cp bin $(ENTRY_POINT)
jar:
ifeq ($(RES_DIR),yes)
jar cvfe $(JAR_PKG) $(ENTRY_POINT) -C bin . res
else
jar cvfe $(JAR_PKG) $(ENTRY_POINT) -C bin .
endif
但我不知道如何将这两个外部 .jar 文件(gson.jar、commons.jar)添加到 makefile 中。而且我不太确定我写的文件路径是否正确。