You need a Java Development Kit (JDK). This includes a Java compiler (usually named javac
), and an jar archiver.
Assuming you have the java files in a directory names src
(then according to their package structure), you would use
javac -d classdir -sourcepath src src/*.java src/*/*.java src/*/*/*.java ...
to compile all files. (Adjust the number of * to the number of directory levels. If you only have some folders with source files in them, you can also list them individually. If some classes depend on others, you can ommit the others, the compiler will find and compile them automatically.)
If the program needs external libraries, provide these with a -classpath
argument.
Now we have all compiled classes in the directory classdir
. Look into your original jar file: any non-class files in there should also copied into your classdir (in the same relative directory they were before). This most notably includes META-INF/MANIFEST.MF
.
Then we create a new jar file from these. The jar
tool is included in the JDK.
jar cfm mypackage.jar classdir/META-INF/MANIFEST.MF -C classdir .
(You can also simply use a zip program of your confidence and rename the resulting zip file to .jar. If your files have non-ASCII names, make sure to set the filename encoding to UTF-8.)