Fast, easy to maintain, and parallelizable way to build java code?
I'm working on a build system that has bad practices piled on other bad practices for a long time and I'm in the process of re-writing the build. The languages involved are C/C++, Fortran, Ada, and Java and for the time being I'm sticking with GNU style makefiles -- though we're considering other alternatives such as SCons.
With that said, I'm looking for some specific recommendations -- not recommendations of the form "use a different build system", etc.
Whoever wrote the particular makefile I'm looking at right now had planned on a sequential build of java code that looks something like this:
LIST_OF_JAVA_FILES = f开发者_JAVA技巧ile1.java
LIST_OF_JAVA_FILES += file2.java
LIST_OF_JAVA_FILES += file3.java
...
LIST_OF_JAVA_FILES += fileN.java
all: ${LIST_OF_JAVA_FILES}
${LIST_OF_JAVA_FILES} : %.class : %.java
${JAVAC} ${CLASSPATH} ${<}
Provided you perform a build in serial, this works fine. However, as soon as dependencies come into the mix it becomes more problematic.
- C/C++ compilers have options built-in for dependency generation ... does a similar facility exist for Java?
- Is it necessary to use third party tools (like Jikes) to generate dependencies?
- Typically speaking, if a team were using makefiles for building anything java related, is it more typical to call the java compiler one time listing out all
.java
files in one command-line -vs- one target for each.class
file?- If this is more common, is this strictly for simplicity sake or is there a deeper reason?
- note: I understand that for a sequential build this would be the faster option, but I want an answer to do empirical tests for parallel builds
We had similar issue in our project. We decided to build all java code via ant and invoke ant from a makefile.
Unless you have a lot of JNI (c++ <----> java) dependencies this might work for you too.
Good luck.
Doing something like
javac -cp MY_CLASSPATH Main.java
suffices most of the time, as it resolves dependences automatically. Sometimes you may need to use more files on the command line, since some of them may get used without an explicit reference.
There are also ant
and maven
and ivy
and whatever, but it's an overkill for something that simple.
It ended up being most expedient (and the norm for java development as a whole) to just specify all source files in a single build step and allow javac
to resolve all the dependencies that way.
精彩评论