fvarrui / JavaPackager

:package: Gradle/Maven plugin to package Java applications as native Windows, MacOS, or Linux executables and create installers for them.
GNU General Public License v3.0
1.07k stars 133 forks source link

There will be some function exceptions when generating custom JRE #228

Closed lhDream closed 2 years ago

lhDream commented 2 years ago

I'm submitting aā€¦

There will be some function exceptions when generating custom JRE. The simplest example:

public static void main(String[] args) {
        try {
            String url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=zh-CNdt=t&q=" + URLEncoder.encode("word", "UTF-8");
            URL serverUrl = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Content-type", "application/json");
            conn.setInstanceFollowRedirects(false);
            conn.connect();
        }catch (Exception e) {
            // javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
            e.printStackTrace();
        }
        System.out.println("Enter any character to end.");
        Scanner scanner = new Scanner(System.in);
        scanner.nextLine();
        scanner.close();
    }

Plug in configuration:

<plugin>
    <groupId>io.github.fvarrui</groupId>
    <artifactId>javapackager</artifactId>
    <version>1.6.6</version>
    <executions>
        <execution>
            <id>bundling-for-windows</id>
            <phase>package</phase>
            <goals>
                <goal>package</goal>
            </goals>
            <configuration>
                <mainClass>${mainClass}</mainClass>
                <platform>windows</platform>
                <bundleJre>true</bundleJre>
                <customizedJre>true</customizedJre>
                <copyDependencies>true</copyDependencies>
                <generateInstaller>false</generateInstaller>
                <winConfig>
                    <headerType>console</headerType>
                    <generateMsi>false</generateMsi>
                    <generateSetup>false</generateSetup>
                </winConfig>
            </configuration>
        </execution>
    </executions>
</plugin>
lhDream commented 2 years ago
System: Windows 10
java version: openjdk version "17.0.2" 2022-01-18
fvarrui commented 2 years ago

Hi @lhDream!

It seems that as your example is using SSL, module jdk.crypto.ec is necessary ... why jdeps is not able to find this module? Because it's implemented as a service, so this module is decoupled of java.base (it's not required). It's explained here.

You can specify this additional module in the JavaPackager configuration:

<additionalModules>
    <additionalModule>jdk.crypto.ec</additionalModule>
</additionalModules>

image

lhDream commented 2 years ago

Hi @fvarrui You're right. How to judge which module is missing or which module is missing?

fvarrui commented 2 years ago

Hi @lhDream! That is a very good question. jdeps helps to find modules which require others explicitly, but with services I really don't know it

fvarrui commented 2 years ago

I'm working on adding support for Java Modules in JavaPackager, and I'm learning about all this. I hope I can find a way to improve the dependencies analysis to avoid these issues

lhDream commented 2 years ago

Hi @fvarrui It may be considered that when the client uses communication related functions, the corresponding module of the server should be added.Or add plug-in support like Lombok? Although I am using jdk17, I don't know much about Java modularity In fact, many people are using java8 :smile:

lhDream commented 2 years ago

I tried creating a modular project and adding the jdk.crypto.ec module, but jedps still can't find the module. :confused:

module test{
    exports test;
    requires jdk.crypto.ec;
    requires java.base;
}

image

fvarrui commented 2 years ago

Hi @fvarrui!

I tried creating a modular project and adding the jdk.crypto.ec module, but jedps still can't find the module. šŸ˜•

It's a bit weird šŸ¤·ā€ā™‚ļø

After some googling, I've found an article which confirms that this could happens, but it doesn't explain why:

image

:slightly_frowning_face:

fvarrui commented 2 years ago

I'm not sure about this, but maybe it's due to jdk.crypto.ec module doesn't export anything:

module jdk.crypto.ec {
    provides java.security.Provider with sun.security.ec.SunEC;
}

It just provides an implementation of the java.security.Provider interface šŸ¤·ā€ā™‚ļø

fvarrui commented 2 years ago

No, this is not the problem šŸ˜ž

I'm not sure about this, but maybe it's due to jdk.crypto.ec module doesn't export anything:

module jdk.crypto.ec {
    provides java.security.Provider with sun.security.ec.SunEC;
}

It just provides an implementation of the java.security.Provider interface šŸ¤·ā€ā™‚ļø

lhDream commented 2 years ago

Maybe because of SPI. šŸ¤” I'm not sure.