3

I am trying to remove the OS-specific chromium binaries to shrink the size of a jar, and install them on first run. I tried to follow the docs, so I removed the -mac, -linux, and -win jxbrowser jars from the pom.xml file, extracted the jxbrowser-mac-6.17.jar into a directory, and set JXBrowser to load the binaries from there, via the following 3 functions (one at a time and combining them):

BrowserPreferences.setChromiumDir(path), System.setProperty("jxbrowser.chromium.dir", path), and System.setProperty(BrowserPreferences.CHROMIUM_DIR_PROPERTY, path)

The specified directory contains the jxbrowser-mac-6.17.jar and its extracted files (7zr-mac, chromium-mac.7z, com and META_INF directories). I am creating a lightweight browser with the following:

BrowserContextParams params = new BrowserContextParams(chromiumDir.getAbsolutePath());
BrowserContext context = new BrowserContext(params);
Browser browser = new Browser(BrowserType.LIGHTWEIGHT, context);

When this code runs, the 7zr-mac and chromium-mac.7z files disappear from the directory, and several errors are thrown, like these:

Caused by: com.teamdev.jxbrowser.chromium.internal.ChromiumExtractorException: Failed to extract Chromium binaries into /Users/bsettle/CytoscapeConfiguration/3/karaf_data/tmp/browsercore-60.0.3112.113.6.17/jxbrowser-mac-6.17
    at com.teamdev.jxbrowser.chromium.internal.ChromiumExtractor.extractChromiumBinariesIfNecessary(SourceFile:88)
    at com.teamdev.jxbrowser.chromium.internal.ipc.IPC.<init>(SourceFile:66)
    at com.teamdev.jxbrowser.chromium.internal.ipc.IPC.create(SourceFile:96)
    at com.teamdev.jxbrowser.chromium.internal.ipc.IPC$a.<clinit>(SourceFile:443)
    ... 7 more
Caused by: java.lang.IllegalArgumentException: The /chromium-mac.7z resource cannot be found in JAR files
    at com.teamdev.jxbrowser.chromium.internal.XZExtractor.a(SourceFile:112)
    at com.teamdev.jxbrowser.chromium.internal.XZExtractor.a(SourceFile:69)
    at com.teamdev.jxbrowser.chromium.internal.XZExtractor.extract(SourceFile:37)
    at com.teamdev.jxbrowser.chromium.internal.b.run(SourceFile:1066)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.teamdev.jxbrowser.chromium.internal.ChromiumExtractor.extractChromiumBinariesIfNecessary(SourceFile:60)
    ... 10 more

All of the errors state that JxBrowser Failed to extract Chromium binaries because The ___ resource cannot be found in JAR files, but it shouldn't be trying to extract them if they already exist in the Chromium directory? (according to the docs).

If I try to open the browser again (pointing to the directory with the binary files now missing, I get a new error:

Exception in thread "Thread-150" java.lang.NoClassDefFoundError: Could not initialize class com.teamdev.jxbrowser.chromium.BrowserContext
    at org.cytoscape.cyndex2.internal.util.BrowserManager.getJXBrowser(BrowserManager.java:72)
    at org.cytoscape.cyndex2.internal.util.BrowserManager.getBrowserView(BrowserManager.java:49)
    at org.cytoscape.cyndex2.internal.task.LoadBrowserTask$1.run(LoadBrowserTask.java:53)
    at java.lang.Thread.run(Thread.java:748)

Even though the base jxbrowser-6.17.jar is still packaged with the app.

I'm not sure what else to try, but I would like to not have to package the OS-specific binaries with the jar because that raises the file size from 8MB to 160MB.

Thanks

1 Answers1

1

Each platform-specific JAR file contains a 7z archive inside with binary files. JxBrowser expects to find the binary files from the corresponding archive in the directory specified by the jxbrowser.chromium.dir System Property and in case they do not exist, tries to extract them. To make it work please extract the binaries from the corresponding archive into the directory specified by the jxbrowser.chromium.dir System Property.

Artem Trofimov
  • 251
  • 1
  • 2