Created
May 7, 2025 16:17
-
-
Save mcgivrer/3fabaa2cd1a1e1fc934c7b5da6a6e8ca to your computer and use it in GitHub Desktop.
java micro build with libs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
project_name=jdemo | |
project_version=1.0.0 | |
main_class=App | |
JARS= | |
vendor_name=DEMO | |
author_name="Frédéric Delorme" | |
#---- | |
GIT_COMMIT_ID=$(git rev-parse HEAD) | |
JAVA_BUILD=$(java --version | head -1 | cut -f2 -d' ') | |
## Prepare Build | |
rm -vrf target/ | |
find src/main/java src/main/resources -name "*.java" | |
mkdir -vp target/{classes,build/libs} | |
## Compile sources | |
javac -cp libs/ $(find src/main/java src/main/resources -name "*.java") -d target/classes | |
## create MANIFEST file | |
echo """ | |
Manifest-Version: ${project_name} | |
Main-Class: ${main_class} | |
Class-Path: ${JARS} | |
Created-By: ${JAVA_BUILD} | |
Implementation-Title: ${project_name} | |
Implementation-Version: ${project_version}-build_${GIT_COMMIT_ID:0:12} | |
Implementation-Vendor: ${vendor_name} | |
Implementation-Author: ${author_name} | |
""" >>target/MANIFEST.MF | |
## create JAR | |
jar cvfe target/build/${project_name}-${main_class}-${project_version}.jar ${main_class} -C target/classes . -C src/main/resources . | |
## prepare run | |
cp -r libs/ target/build/libs | |
echo "project Compiled, now run it !" | |
java -cp libs/ -jar target/build/${project_name}-${main_class}-${project_version}.jar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Java project inspired from maven structure :
build is the bash script.
You need to define the following variables in the script:
Defining the jar output :
List jar dependencies for build and run :
libs/
]Define entries for MANIFEST: