Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11661

Using a Makefile for Java

$
0
0

For college, I have to use Java. However, I do not want to use an IDE. I like vim.

So I'm trying to create a Makefile to build my java projects. My requirements are :

  1. No hardcoding of classes. The Makefile shall find all .java files in the src directory and any subdirectories, and compile the resulting classes to the classes directory.

  2. Multiple mains : Files containing main functions shall have an executable .jar file built with a corresponding MANIFEST.MF. Listing them explicitly is acceptable, although I'm pretty sure something could be done with grep here to find them automatically (but I suck at grep)

  3. A source jar for the whole project shall be created, containing unaltered .java files and no MANIFEST.MF or other extraneous files.

My best attempt so far (currently broken) follows :

include gmsltargets := Client Server# Folders binDir  := ./binclsDir  := ./classessrcDir  := ./srctestDir := ./test# Flagsversion := 11# FilesmainSrc := $(targets:%=$(srcDir)/tp1/%.java)src  := $(shell find $(srcDir) -name *\.java -type f)cls  := $(src:%.java=%.class)# Rules# Baseall     : $(targets)again   : clean allclasses : $(cls)# For debuginfo:    $(info mainSrc : $(mainSrc))    $(info srcJar  : $(srcJar))    $(info exeJar  : $(exeJar))    $(info src     : $(src))    $(info cls     : $(cls))# Executables$(targets): $(cls)    $(shell cd $(srcDir))    $(eval mainCls := $(shell find . -name *$@\.java -type f) )    $(info mainCls = $(mainCls))    jar --verbose --create --file=$(call lc,$@)-exe.jar --main-class=tp1/$@ -C $(clsDir) .# Source$(srcJar) : $(cls)    jar --verbose --create --file=$@ --no-manifest -C $(srcDir) .# Classes$(cls):    javac --release $(version) --source-path $(srcDir) -d $(clsDir) $(mainSrc)# Cleanupclean:    -rm $(targets)    -cd $(clsDir) && rm -rf ./*

Viewing all articles
Browse latest Browse all 11661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>