First of all I want to say that I do not want to use Maven, Ant, Gradle, any IDE or similar for this task.
I want to make a runnable jar using a bash script. The jar should includes all jar-content from my "libs" folder.
I have started this script and it "almost" works(until the jar creattion):
#!/bin/bash
#Setup
libs=$(find libs -name "*.jar" -print0 | xargs -0 | sed -e 's/ /:/g')
tmp2=$(sed -e 's/:/\n ..\//g' <<< $libs)
tmp2=../$tmp2
libs=$libs:src
mkdir tmp
#Compile
javac -d tmp -classpath "$libs" src/main/PublishData.java
#Create manifest
cd tmp
echo "Main-Class: main.PublishData" >> m.mf
echo "Class-Path: $tmp2" >> m.mf
#Build jar
jar cvfm thejar.jar m.mf *
An m.mf example file would look like this:
Main-Class: MyMain
Class-Path: ../libs/1.jar
../libs/2.jar
The file structure looks like this:
├── src
├── tmp (created by the script, jar cvfm thejar.jar m.mf * is run here)
├── libs
│ ├── jar1
│ ├── jar2
The jar file is created and can be executed but the referenced jars are not found.
(E.g: Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/MongoClient
)
It seams to me like the jar program could not find the jars.
How can I successfully "include" my jars from the libs dir?
UPDATE:
Every line in the "Class-Path:" section of a manifest file needs to start and end with a white space this caused the class-path to break.