Skip to content

jvmArgs "--add-opens" has no effect!? #274

Description

@SaluRamos

Hi, run task works fine, but when running the executable generated by jpackage task i got openCV errors. There are this lib called 'dcm4che' that uses opencv to decompress medical images, and i need to add opencv path to the java.library.path, what is wrong?

this is build.gradle file:

plugins {
    id "java"
    id "application"
    id "org.openjfx.javafxplugin" version "0.0.13"
    id "org.beryx.jlink" version "2.25.0" //https://github.com/beryx/badass-jlink-plugin
    id "org.javamodularity.moduleplugin" version "1.8.12"
}

group "com.webkriativa.noahviewer"
version "0.5"

var lwjglNativesPath = "libs/lwjgl";
var dcm4cheVersion = "5.31.2"
var dcm4chePath = "libs/dcm4che-" + dcm4cheVersion;
var openCVNativesWindowsPath = dcm4chePath + "/lib/windows-x86-64"
project.ext.lwjglVersion = "3.3.3"
project.ext.lwjglNatives = "natives-windows"

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

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 {
   ....a lot of lines...
}

tasks.jpackageImage.doLast {
    copy {
        from("src/main/resources")
        into("$buildDir/jpackage/$project.name/src/main/resources")
    }
    copy {
        from "libs"
        into("$buildDir/jpackage/$project.name/libs")
    }
}

jlink{
    forceMerge('log4j-api')
    forceMerge('slf4j-api-2.0.9')
    mergedModule {
        additive = true
        uses 'org.apache.logging.log4j.util.PropertySource';
        uses 'org.apache.logging.log4j.spi.Provider';
        uses 'org.apache.logging.log4j.message.ThreadDumpMessage.ThreadInfoFactory';
    }
    jpackage {
        if (org.gradle.internal.os.OperatingSystem.current().windows) {
            installerOptions += ['--icon', 'src/main/resources/images/logo.ico']
            imageOptions += ['--win-console']
            imageOptions += ['--resource-dir', 'src/main/resources']
            icon = "src/main/resources/images/logo.ico"
            skipInstaller = true
        }
    }
    launcher{
        jvmArgs = ['-Djava.library.path="' + lwjglNativesPath + ";" + dcm4chePath + ';' + openCVNativesWindowsPath + '"',
                   '--add-opens', 'java.desktop/javax.imageio.stream=dcm4che.imageio.opencv',
                   '--add-opens', 'java.base/java.io=dcm4che.imageio.opencv']
    }
}

run {
    jvmArgs = ['-Djava.library.path="' + lwjglNativesPath + ";" + dcm4chePath + ';' + openCVNativesWindowsPath + '"',
               '--add-opens', 'java.desktop/javax.imageio.stream=dcm4che.imageio.opencv',
               '--add-opens', 'java.base/java.io=dcm4che.imageio.opencv']
}

error:

org.opencv.osgi.OpenCVNativeLoader init
Successfully loaded OpenCV native library.
java.lang.NullPointerException: Cannot invoke "org.dcm4che3.opencv.StreamSegment.getImageDescriptor()" because "seg" is null

this error occurs only when not using the "--add-opens", why add-opens in jvmArgs has not effect in the exe?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions