javafx应用程序映像与javafx应用程序运行时中jgit的ssl证书颁发

javafx应用程序映像与javafx应用程序运行时中jgit的ssl证书颁发,ssl,javafx,jgit,Ssl,Javafx,Jgit,我使用jgit开发了一个简单的JavaFX应用程序,允许用户使用git 当应用程序从IntelliJ idea启动时,我能够使用“git clone”命令的jgit实现克隆GitHub repo,没有任何问题。但是,一旦我从应用程序创建了一个映像并从映像启动应用程序,我就会收到一个SSL证书问题: 异常:org.eclipse.jgit.api.errors.TransportException: 由于SSL问题,无法建立到的安全连接 我试图理解为什么只有在从映像运行应用程序时才会出现SSL证书

我使用jgit开发了一个简单的JavaFX应用程序,允许用户使用git

当应用程序从IntelliJ idea启动时,我能够使用“git clone”命令的jgit实现克隆GitHub repo,没有任何问题。但是,一旦我从应用程序创建了一个映像并从映像启动应用程序,我就会收到一个SSL证书问题:

异常:org.eclipse.jgit.api.errors.TransportException: 由于SSL问题,无法建立到的安全连接

我试图理解为什么只有在从映像运行应用程序时才会出现SSL证书问题。有人能解释一下吗?我知道我可以禁用SSL验证(在这个主题上有一些问题可以回答),但我想知道为什么它是从IDE而不是从创建的映像工作的

以下是我针对http的简化git克隆实现:

try { 

            CloneCommand command = Git.cloneRepository();

            command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(httpUsername, httpPassword));

            // run the clone command
            command.setURI(repositoryUrl);
            command.setDirectory(dirFramework);
            git = command.call();

} catch (Exception e) {
    LOG.error("Error occurred during task: Git clone: " + e);
}
为了创建图像,我使用了带有Gradle任务“runtime”的“org.beryx.runtime”插件

这是build.gradle的内容:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.runtime' version '1.11.4'
}

group 'org.sovap'
version '1.0-SNAPSHOT'

sourceCompatibility = 11
targetCompatibility = 11

repositories {
    mavenCentral()
}

dependencies {

    // xml stuff
    compile 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
    compile 'jakarta.activation:jakarta.activation-api:1.2.2'

    // logger
    compile 'org.apache.logging.log4j:log4j-core:2.13.3'
    compile 'org.slf4j:slf4j-api:1.7.30'
    compile 'org.slf4j:slf4j-simple:1.7.30'

    // cucumber
    compile 'io.cucumber:gherkin:15.0.2'

    // jgit
    compile 'org.eclipse.jgit:org.eclipse.jgit:5.9.0.202009080501-r'
    compile 'org.eclipse.jgit:org.eclipse.jgit.archive:5.9.0.202009080501-r'
    compile 'org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:5.9.0.202009080501-r'

    // file utils
    compile 'commons-io:commons-io:2.7'

    //controlsfx
    compile 'org.controlsfx:controlsfx:11.0.2'

}

javafx {
    version = "15"
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', "javafx.graphics"]
}

application {
    mainClassName = 'org.sovap.taman.Launcher'
    applicationName = 'taman'
}

runtime {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    imageDir = file("$buildDir/taman")
}
编辑1:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.runtime' version '1.11.4'
}

group 'org.sovap'
version '1.0-SNAPSHOT'

sourceCompatibility = 11
targetCompatibility = 11

repositories {
    mavenCentral()
}

dependencies {

    // xml stuff
    compile 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
    compile 'jakarta.activation:jakarta.activation-api:1.2.2'

    // logger
    compile 'org.apache.logging.log4j:log4j-core:2.13.3'
    compile 'org.slf4j:slf4j-api:1.7.30'
    compile 'org.slf4j:slf4j-simple:1.7.30'

    // cucumber
    compile 'io.cucumber:gherkin:15.0.2'

    // jgit
    compile 'org.eclipse.jgit:org.eclipse.jgit:5.9.0.202009080501-r'
    compile 'org.eclipse.jgit:org.eclipse.jgit.archive:5.9.0.202009080501-r'
    compile 'org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:5.9.0.202009080501-r'

    // file utils
    compile 'commons-io:commons-io:2.7'

    //controlsfx
    compile 'org.controlsfx:controlsfx:11.0.2'

}

javafx {
    version = "15"
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', "javafx.graphics"]
}

application {
    mainClassName = 'org.sovap.taman.Launcher'
    applicationName = 'taman'
}

runtime {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    imageDir = file("$buildDir/taman")
}
如何创建图像?-图像是使用插件“org.beryx.runtime”版本“1.11.4”创建的,Gradle任务名为“runtime”。在build.gradle内容的末尾,您可以看到运行时任务的一些特定配置

此外,还可以包括此处所述的模块:

我已经在build.gradle中用您提到的运行时任务模块测试了配置(也一个接一个):

但在从图像启动应用程序时,我遇到了以下异常:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException
        at org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory.newConfigurationBuilder(ConfigurationBuilderFactory.java:38)
        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.<init>(PropertiesConfigurationBuilder.java:72)
        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:52)
        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:35)
        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:551)
        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:475)
        at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:323)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:687)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:708)
        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:602)
        at org.sovap.taman.App.<clinit>(App.java:15)
        at org.sovap.taman.Launcher.main(Launcher.java:6)
Caused by: java.lang.ClassNotFoundException: javax.xml.stream.XMLStreamException
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 16 more

现在一切正常。

最可能的情况是JRE映像中缺少一个与加密相关的模块,该模块是验证SSL连接所必需的

最终映像中有哪些jdk.crypto.*模块? 如果其中一个丢失,可能会影响处理SSL证书的能力

  • jdk.crypto.cryptoki
  • jdk.crypto.ec
  • jdk.crypto.mscapi
由于安全/加密代码的某些方面是通过服务提供商完成的,因此在生成JRE映像时,您可能应该通过 --将“绑定服务”选项设置为“链接服务提供程序模块及其依赖项”

您需要分享有关如何创建映像以及报告哪些特定错误的更多详细信息。尝试包含所有报告异常的完整堆栈跟踪

您使用的是什么版本的Java11? 你可能会遇到这样的情况:


(如果您在IDE和打包映像中使用的是相同的JDK版本,这是不可能的,但我想我会提到它,以防它给您一个提示。)

请分享您遇到的任何异常。我已编辑了该问题。感谢您的时间和努力。为异常添加整个堆栈跟踪。例如,有没有提到“由”引起的?stacktrace中没有其他内容,只是:2020-11-12 10:09:47727[ERROR][Thread-5]taman.utils.GitUtils-任务期间发生错误:Git clone:org.eclipse.jgit.api.errors.TransportException::由于SSL问题,无法建立到的安全连接,谢谢您的回答,我已经添加了build.gradle内容。其他的一切都已经存在了(例外和图像的准备方式…),我把它加粗了,因为它更明显了。关于您的回答,您提到了一个与加密相关的模块。你能详细说明一下吗?感谢您的时间和努力。我已经找到了使用您建议的模块的解决方案。非常感谢你!
runtime {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    imageDir = file("$buildDir/taman")
    modules = [
            'java.desktop',
            'java.logging',
            'java.xml',
            'java.compiler',
            'java.datatransfer',
            'java.rmi',
            'java.sql',
            'java.naming',
            'java.scripting',
            'java.management',
            'java.security.jgss',
            'jdk.jfr',
            'java.net.http',
            'jdk.jsobject',
            'jdk.xml.dom',
            'jdk.unsupported',
            'jdk.crypto.cryptoki',
            'jdk.crypto.ec',
            'jdk.crypto.mscapi']
}