Skip to content

Instantly share code, notes, and snippets.

@SyntaxCacao
Last active July 7, 2016 19:43
Show Gist options
  • Save SyntaxCacao/e57b553e6fbe99ed7cc6 to your computer and use it in GitHub Desktop.
Save SyntaxCacao/e57b553e6fbe99ed7cc6 to your computer and use it in GitHub Desktop.
Compiles Java source code and puts it into a jar file.
@echo off
if not exist src (
echo Missing 'src\' folder. Creating one for you.
echo.
mkdir src
@echo Main-Class: MyPackage.MyClass> src\Manifest.txt
pause
exit /b
)
if not exist src\Manifest.txt (
echo Missing 'src\Manifest.txt'. Creating one for you.
echo Remember updating the Main-Class value!
echo.
@echo Main-Class: MyPackage.MyClass> src\Manifest.txt
pause
exit /b
)
if "%JAVA_HOME%" == "" (
echo Missing required environment variable JAVA_HOME.
echo.
pause
exit /b
)
echo Starting build process
echo.
if not exist tmp (
mkdir tmp
attrib +h tmp
)
if exist bin (
echo - Clearing 'bin\'
rmdir /s /q bin
)
echo - Making sources.txt
cd src
dir /s /b *.java > ..\tmp\sources.txt
cd ..
echo - Compiling into 'bin\'
mkdir bin
"%JAVA_HOME%\bin\javac.exe" -d bin -encoding UTF-8 @tmp\sources.txt
if exist application.jar (
echo - Deleting old jar
del application.jar
)
echo - Creating new jar
cd bin
"%JAVA_HOME%\bin\jar.exe" cfm ..\application.jar ..\src\Manifest.txt *
cd ..
if exist res (
echo - Including resources
cd res
"%JAVA_HOME%\bin\jar.exe" uf ..\application.jar *
cd ..
)
echo.
echo Done.
echo.
pause
#!/bin/bash
if [ ! -d src ]
then
echo "Missing 'src/' directory. Creating one for you."
echo ""
mkdir src
echo "Main-Class: MyPackage.MyClass" > src/Manifest.txt
exit
fi
if [ ! -e src/Manifest.txt ]
then
echo "Missing 'src/Manifest.txt'. Creating one for you."
echo "Remember updating the Main-Class value!"
echo ""
echo "Main-Class: MyPackage.MyClass" > src/Manifest.txt
exit
fi
echo "Starting build process"
echo ""
echo " - Making sources.txt"
if [ ! -d .tmp ]
then
mkdir .tmp
fi
find src -type f -name *.java > .tmp/sources.txt
if [ -d bin ]
then
echo " - Clearing 'bin/'"
rm -r bin
fi
echo " - Compiling into 'bin/'"
mkdir bin
javac -d bin -encoding UTF-8 @.tmp/sources.txt
if [ -a application.jar ]
then
echo " - Deleting old jar"
rm application.jar
fi
echo " - Creating new jar"
cd bin
jar cfm ../application.jar ../src/Manifest.txt *
cd ..
if [ -d res ]
then
echo " - Including resources"
cd res
jar uf ../application.jar *
cd ..
fi
echo ""
echo "Done."
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment