Search code examples
gradleintellij-ideabuild

build gradle project in Intellij with local libraries


I need to generate a jar file of my project. This is my first time using gradle.

Inside intellij, i'm executing "gradle -> Tasks -> jar" to generate the jar file. The jar file is generated inside "build -> libs", opening the prompt inside the directory, i can execute the command:

java -jar .\gradle-project.jar (I ensured that the version of java executed at the prompt is the same as that configured in intellij)

But console prints:

java.lang.UnsatisfiedLinkError: no SimpleITKJava in java.library.path

I know what this error is, this error occurs when java can't find one of the gradle library called SimpleITK, there is no online repository for this library, so I downloaded the library and configured gradle to use the local files. In my run / debug configuration, i put this in VM options:

-Djava.library.path="D:\path-to-gradle-project\libs\SimpleITK-2.3.0"

this VM options fix the error, so it should fix for prompt too right?

Then, when i try:

java -Djava.library.path="D:\path-to-gradle-project\libs\SimpleITK-2.3.0" -jar .\gradle-project.jar

console prints:

Error: Could not find or load main class .library.path=D:\path-to-gradle-project\libs\SimpleITK-2.3.0
Caused by: java.lang.ClassNotFoundException: /library/path=D:\path-to-gradle-project\libs\SimpleITK-2/3/0

What is wrong? Thanks for reading this far! This is my build.gradle file:

plugins {
    id 'java'
    id 'application'
    id 'org.javamodularity.moduleplugin' version '1.8.12'
    id 'org.openjfx.javafxplugin' version '0.0.13'
    id 'org.beryx.jlink' version '2.25.0'
}

group 'com.webkriativa.noahviewer'
version '0.3'

repositories {
    mavenCentral()
    maven {
        url = uri("https://maven.scijava.org/content/repositories/public/")
    }
}

sourceCompatibility = '17'
targetCompatibility = '17'

tasks.withType(JavaCompile).configureEach {
    options.encoding = 'UTF-8'
}

application {
    mainModule = 'com.webkriativa.noahviewer'
    mainClass = 'com.webkriativa.noahviewer.Main'
}

javafx {
    version = '17.0.6'
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics']
}

dependencies {
    implementation files("libs/SimpleITK-2.3.0/simpleitk-2.3.0rc2.jar")

    implementation("org.dcm4che:dcm4che-core:5.31.0")
    implementation("org.dcm4che:dcm4che-imageio:5.31.0")
    implementation("org.dcm4che.tool:dcm4che-tool-common:5.30.0")

    implementation("javax.media:jai-core:1.1.3")

    compileOnly("org.projectlombok:lombok:1.18.28")
    annotationProcessor("org.projectlombok:lombok:1.18.28")
    testCompileOnly("org.projectlombok:lombok:1.18.28")
    testAnnotationProcessor("org.projectlombok:lombok:1.18.28")
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
    implementation("org.apache.commons:commons-csv:1.10.0")
    implementation("org.openjfx:javafx-controls:20.0.2")
    implementation("org.openjfx:javafx-graphics:20.0.2")
    implementation("org.openjfx:javafx-base:20.0.2")

}

test {
    useJUnitPlatform()
}

jar {
    manifest {
        attributes 'Main-Class' : 'com.webkriativa.noahviewer.Main'
    }

    duplicatesStrategy = 'exclude'

    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }

}

Solution

  • I solve this problem like this: java -D"java.library.path"="D:\my-project-path\libs\SimpleITK-2.3.0" -jar .\build\libs\my-project.jar