Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with loading resources from src/main/deploy (i.e. icons) [JDK 10] #326

Open
maxd opened this issue Mar 2, 2018 · 2 comments
Open

Comments

@maxd
Copy link
Contributor

maxd commented Mar 2, 2018

I have tried to build my application with JDK 10 EAP b45 because it going to be released this month and noticed that my Mac OS app have default app icon. I have dig deeper and found that jdk.packager.internal.legacy.builders.AbstractAppImageBuilder#locateResource doesn't load resources from class path by default anymore. Look at this code and my comments:

protected InputStream locateResource(String publicName, String category,
                                     String defaultName, File customFile,
                                     boolean verbose, File publicRoot) throws IOException {
    InputStream is = null;
    boolean customFromClasspath = false;
    boolean customFromFile = false;
    if (publicName != null) {
        if (publicRoot != null) { // <=== This is value from `dropinResourcesRoot` parameter and by default it equla to `.` (seems like it mean project root)
            File publicResource = new File(publicRoot, publicName);
            if (publicResource.exists() && publicResource.isFile()) {
                is = new FileInputStream(publicResource);
            }
        } else {
            is = getResourceAsStream(publicName); // <=== This method can load icon from class path but looks like new JDK doesn't allow it
        }
        customFromClasspath = (is != null);
    }
    if (is == null && customFile != null) {
        is = new FileInputStream(customFile);
        customFromFile = (is != null);
    }
    if (is == null && defaultName != null) {
        is = getResourceAsStream(defaultName); // <=== Here is loading default icon
    }
    String msg = null;
    if (customFromClasspath) {
        msg = MessageFormat.format(I18N.getString("message.using-custom-resource-from-classpath"), category == null ? "" : "[" + category + "] ", publicName);
    } else if (customFromFile) {
        msg = MessageFormat.format(I18N.getString("message.using-custom-resource-from-file"), category == null ? "" : "[" + category + "] ", customFile.getAbsoluteFile());
    } else if (is != null) {
        msg = MessageFormat.format(I18N.getString("message.using-default-resource-from-classpath"), category == null ? "" : "[" + category + "] ", publicName);
    } else {
        msg = MessageFormat.format(I18N.getString("message.using-default-resource"), category == null ? "" : "[" + category + "] ", publicName);
    }
    if (verbose) {
        Log.info(msg);
    }
    return is;
}

This method is called from jdk.packager.internal.legacy.builders.mac.MacAppImageBuilder#prepareApplicationFiles:

...

/*********** Take care of "config" files *******/
// Copy icon to Resources folder
File icon = ICON_ICNS.fetchFrom(params);
InputStream in = locateResource("package/macosx/" + APP_NAME.fetchFrom(params) + ".icns",
        "icon",
        DEFAULT_ICNS_ICON.fetchFrom(params),
        icon,
        VERBOSE.fetchFrom(params),
        DROP_IN_RESOURCES_ROOT.fetchFrom(params));
Files.copy(in, resourcesDir.resolve(APP_NAME.fetchFrom(params) + ".icns"));

...

So, to fix this problem need to specify path to src/main/deploy in dropinResourcesRoot parameter:

<plugin>
    <groupId>com.zenjava</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>8.9.0-SNAPSHOT</version>
    <configuration>
        <bundleArguments>
            ...
            <dropinResourcesRoot>${project.basedir}/src/main/deploy</dropinResourcesRoot>
            ...
        </bundleArguments>
    </configuration>
</plugin>

As well I think initialization of class path here is not required anymore. Moreover it print the following warnings:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.zenjava.javafx.maven.plugin.AbstractJfxToolsMojo (file:/Users/closer/.m2/repository/com/zenjava/javafx-maven-plugin/8.9.0-SNAPSHOT/javafx-maven-plugin-8.9.0-SNAPSHOT.jar) to method java.net.URLClassLoader.addURL(java.net.URL)
WARNING: Please consider reporting this to the maintainers of com.zenjava.javafx.maven.plugin.AbstractJfxToolsMojo
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

So, looks like it should be removed it in the future.

@FibreFoX FibreFoX self-assigned this Mar 3, 2018
@FibreFoX FibreFoX added the JDK 10 label Mar 3, 2018
@FibreFoX
Copy link
Member

Everytime there is a workaround using that <bundleArguments>-map, I'm happy ;) thanks for pointing to that issue.

@FibreFoX
Copy link
Member

@Aashishkapadiya asking for ETA on spare-time, non-profit open source projects? Really?

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

No branches or pull requests

2 participants