'Building a Jar using gradle - Jar hasn't sql dependency [duplicate]

I am trying to build a very simple Program. I only have one dependency, the msql-jdbc.

Every build succeds. But if i try to run the jar this exception ist thrown:

Error: Could not find or load main class metaDataDB-0.5-msSQL.jar Caused by: java.lang.ClassNotFoundException: metaDataDB-0.5-msSQL.jar

If i look into the jar, for example 7zip, I see all my compiled Classes.

The content of MANIFEST.MF is as follows:

Manifest-Version: 1.0
Main-Class: metaDataDB.Main

Maybe this helps: Project Structure in Intellij

Here is my full build:

plugins {
    id 'java'
}

jar{
    manifest {
        attributes 'Main-Class': 'metaDataDB.Main'
    }
}

repositories {
    mavenCentral()
}

group 'com.dvb'
//version '1.0-SNAPSHOT'
version '0.5-msSQL'
sourceCompatibility = 17


dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
    // https://mvnrepository.com/artifact/org.postgresql/postgresql
    //implementation group: 'org.postgresql', name: 'postgresql', version: '42.3.1'
    // / https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
    // https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
    implementation group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '9.5.0.jre17-preview'
}

test {
    useJUnitPlatform()
}

Did I setup something wrong? Is this an Intellij error? I am really confused. I think it should work...

EDIT: I did the mistake that i did a wrong java command. The way i did it before:

java metaDataDB-0.5-msSQL.jar -login:login.txt

The right way to do it:

java -jar metaDataDB-0.5-msSQL.jar -login:login.txt

But know I have another Problem. My jdbc driver isn't included in the Jarfile Jarfile Contents



Solution 1:[1]

the problem exists in msSQL.jar, there are some missing classes I guess, you can go to https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc and Implement the right jar for your JRE or experiment with different versions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yahyaBdd