Regular JAR file with dependencies

I’m not trying to build a fat JAR, or uberjar. I want a “non-fat” JAR file. But, I also want to include the run-time dependencies. I have no idea what this is called, everything seems to revolve around fat JAR files.

What I want to is to build JAR’s the way it’s described in the tutorials for Java SE on the Oracle website. What they specify is to use the Class-Path attribute in the JAR manifest. Here’s what I have.

thufir@doge:~/NetBeansProjects/Firebase$ 
thufir@doge:~/NetBeansProjects/Firebase$ gradle clean jar

BUILD SUCCESSFUL in 5s
4 actionable tasks: 4 executed
thufir@doge:~/NetBeansProjects/Firebase$ 
thufir@doge:~/NetBeansProjects/Firebase$ java -jar build/libs/Firebase.jar 
Jul 08, 2017 7:06:34 PM net.bounceme.dur.firebase.Main main
INFO: init..
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/firebase/database/ValueEventListener
	at net.bounceme.dur.firebase.Main.<init>(Main.java:13)
	at net.bounceme.dur.firebase.Main.main(Main.java:17)
Caused by: java.lang.ClassNotFoundException: com.google.firebase.database.ValueEventListener
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 2 more
thufir@doge:~/NetBeansProjects/Firebase$ 
thufir@doge:~/NetBeansProjects/Firebase$ cd build/libs/
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ 
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ ll
total 24
drwxrwxr-x 2 thufir thufir  4096 Jul  8 19:06 ./
drwxrwxr-x 6 thufir thufir  4096 Jul  8 19:06 ../
-rw-rw-r-- 1 thufir thufir 15097 Jul  8 19:06 Firebase.jar
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ 
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ jar -xf Firebase.jar 
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ 
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ ll
total 44
drwxrwxr-x 5 thufir thufir  4096 Jul  8 19:06 ./
drwxrwxr-x 6 thufir thufir  4096 Jul  8 19:06 ../
drwxrwxr-x 3 thufir thufir  4096 Jul  8 19:06 com/
-rw-rw-r-- 1 thufir thufir 15097 Jul  8 19:06 Firebase.jar
-rw-rw-r-- 1 thufir thufir    37 Jul  8 19:06 firebase.properties
drwxrwxr-x 2 thufir thufir  4096 Jul  8 19:06 META-INF/
drwxrwxr-x 3 thufir thufir  4096 Jul  8 19:06 net/
-rw-rw-r-- 1 thufir thufir  2338 Jul  8 19:06 serviceAccountKey.json
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ 
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ nl META-INF/MANIFEST.MF 
     1	Manifest-Version: 1.0
     2	Class-path: firebase-admin-5.2.0.jar
     3	Main-Class: net.bounceme.dur.firebase.Main
     4	
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ 
thufir@doge:~/NetBeansProjects/Firebase/build/libs$ cd ..
thufir@doge:~/NetBeansProjects/Firebase/build$ cd ..
thufir@doge:~/NetBeansProjects/Firebase$ 
thufir@doge:~/NetBeansProjects/Firebase$ cat build.gradle
plugins {
    id 'com.gradle.build-scan' version '1.8' 
    id 'java'
    id 'application'
}

    
mainClassName = 'net.bounceme.dur.firebase.Main'


buildScan {
    licenseAgreementUrl = 'https://gradle.com/terms-of-service'
    licenseAgree = 'yes'
}

repositories {
    jcenter()
}

jar {
    manifest {
        attributes 'Main-Class': 'net.bounceme.dur.firebase.Main'
        attributes 'Class-path': 'firebase-admin-5.2.0.jar'
    }
}

dependencies {
    //compile fileTree(dir: 'libs', include: ['*.jar'])

    // https://mvnrepository.com/artifact/com.google.firebase/firebase-admin
    compile group: 'com.google.firebase', name: 'firebase-admin', version: '5.2.0'

    // https://mvnrepository.com/artifact/com.google.firebase/firebase-server-sdk
  //  compile group: 'com.google.firebase', name: 'firebase-server-sdk', version: '3.0.3'

    // https://mvnrepository.com/artifact/com.firebase/firebase-client-jvm
  //  compile group: 'com.firebase', name: 'firebase-client-jvm', version: '2.5.2'



    // https://mvnrepository.com/artifact/com.google.firebase/firebase-admin
    runtime group: 'com.google.firebase', name: 'firebase-admin', version: '5.2.0'

    // https://mvnrepository.com/artifact/com.google.firebase/firebase-server-sdk
//    runtime group: 'com.google.firebase', name: 'firebase-server-sdk', version: '3.0.3'

    // https://mvnrepository.com/artifact/com.firebase/firebase-client-jvm
  //  runtime group: 'com.firebase', name: 'firebase-client-jvm', version: '2.5.2'
}
thufir@doge:~/NetBeansProjects/Firebase$ 

see also:

Hello,

I think your issue is that the JVM cannot find the jar mentionned in the Class-Path entry in the current jar.
When applying the application plugin, your application is packaged as zip and tar archives. You need to run the java -jar command in the lib folder of one of these archives.

In short, try these commands:

# Expand archive somewhere, can also use unzip if you want
tar xf build/distributions/*.tar -C somewhere/
# Run main class
java -jar somewhere/your_app_name/lib/Firebase.jar