Domanda

I have an app that is using jnlp as the launcher. It uses the Sigar libraries which require dynamically loaded native libraries for platform specific code.

For purposes of debugging this I have two JNLP files, one that references the codebase using file: urls and the other using http: urls. The http urls point to localhost apache which is properly serving the files. I can watch JNLP download them during its launch sequence via apache logs so I know the files are getting to my app properly.

Here are the two codebase tags

codebase="file:/Users/siberian/Documents/workspace_mnis/MNIS/localhost/" 
href="file:/Users/siberian/Documents/workspace_mnis/MNIS/localhost/minis.jnlp"-->

and codebase="http://localhost/" href="http://localhost/mnis.jnlp"

If I double click the file: version it works fine. If I load it via my browser it works fine.

If I double click or browser load the http: version it fails to find the dynamic libraries with this error:

JNLPClassLoader: Finding library liblibsigar-universal64-macosx.dylib.dylib
[AWT-EventQueue-0] DEBUG Sigar  - no libsigar-universal64-macosx.dylib in java.library.path
org.hyperic.sigar.SigarException: no libsigar-universal64-macosx.dylib in java.library.path

Now, the interesting to note is that file that it says it cant find liblibsigar-universal64-macosx.dylib.dylib

Note the prefix extra 'lib' and postfix extra '.dylib'.

There are notes on the Sigar/vmware forums about similar problems with no solutions.

The core question is, why is this acting differently in a file: context vs an http: context?

Also of note, I have unsigned and resigned all of my files, there are no signature errors that I can see.

There are hints at an answer here: Java Webstart with Tibco Native Libs

But it works in a file: context which makes me think something else is wrong.

Also: JaNeLa tells me all is fine

È stato utile?

Soluzione

JNLP and Sigar classloaders do not play well together. This was pieced together but works well in both Windows and Mac environments. The VMWare forums HINT at an answer like this but no one has put it all together. For JNLP you need to specifically do a loadLibrary based on your architecture. In a non-JNLP context Sigar handles this transparently but JNLP breaks that somehow, requiring this manual platform selection.

Just put this method into your class and call it BEFORE you call new Sigar() and it should work properly. This solutions requires the commons-lang library. You can easily extend this for linux and other alternate platform support.

 private static void preloadSigar() {

        String arch = System.getProperty("os.arch");
        String libName;

        if (SystemUtils.IS_OS_WINDOWS) {
            if (arch.equalsIgnoreCase("x86")) 
                libName = "sigar-x86-winnt";
            else
                libName = "sigar-amd64-winnt";
        } else if (SystemUtils.IS_OS_MAC_OSX) {
            if (arch.startsWith("i") && arch.endsWith("86"))
                libName = "sigar-universal-macosx";
            else
                libName = "sigar-universal64-macosx";
        } else {
            throw new RuntimeException("Unrecognized platform!");

        }

        System.setProperty("org.hyperic.sigar.path", "-");    
        System.loadLibrary(libName);

      }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top