Going from a bunch of .Java files to a .Jar file from the commandline with one simple command
-
13-12-2019 - |
Question
I've searched around and I can't find a simple commandline tool that will take a bunch of .java files in a directory and compile to .class files then stick them all in a .jar automatically. I could probably write a script myself but this is one area where I have no interest in reinventing the wheel whatsoever (I'll code up Djikstra's algorithm a million times but I really don't want to waste time on something like this).
Is there a simple tool similar to gcc or ghc which you can just navigate to a directory and invoke upon the files therein in order to produce an executable jar file? I had hope for gcj, but apparently that compiles down to 0s and 1s. Awesome, but not what I'm looking for.
Please don't suggest IDEs. I don't want to deal with netbeans, eclipse, bluej etc. They are amazing pieces of software, but I'm not writing enterprise code and would rather bash it out in a simple text editor.
Cheers!
Solution
The two standard tools for this are:
Don't require use of an IDE, but will do exactly what you're looking for in a clean and standard manner.
OTHER TIPS
Ant definitely can do what you need. This might help if you have a simple project:
Given the current directory as:
src (where source java files live)
classes (where we are going to put compiled classes)
Windows:
mkdir classes
dir /s/b src\*.java > list.java
javac -d classes -sourcepath src @list.java
jar -cf myjar.jar -C classes .
Same should work on linux environs using
find . -name \*.java > list.java
instead of the dir /s/b... for windows.