Need help making a plugin using native libraries

Good day.

I’m trying to get a specific jar containing DLLs for windows or dylibs for mac os to be loaded but for whatever reason this doesn’t work with Servoy altough it should work according to the official JNLP doc.

Is there any way to have a servoy plugin with a set of native librairies loaded into any of Java’s “native library path” locations by the plugin’s JNLP or is there any existing plugins that use native librairies that I could look at as an example?

Thanks for your help…

Stefan

Hi Stefan,

nice to see that I am not the only one with crazy ideas around here, and a fellow Quebecois too ;-)

I have been able to load native libs for windows from servoy, but unfortunately haven’t had any success with Mac OS yet, but then again the Mac OS implementation of JWS is so quirky that Sun (Oracle ?) don’t even wan’t to know about it…

Basically, I didn’t use the node but a plain node instead. I found it working on Win32, but on Mac there are some very weird thing happening (like one of my colleague who’s using Parallels to run windows have seen windows being launched by JNLP on a Mac!!!), and I didn’t found out yet. it would help if I had a Mac to play with, but it’s not the case so I have to bother my colleagues and ask them to clear their java cache, etc… to test my new JNLP :{

If you want, you can contact me by PM, I too am really interested in making it work and maybe you will have better access to a Mac than I.

Cheers,

Hi Patrick,

ptalbot:
I found it working on Win32, but on Mac there are some very weird thing happening (like one of my colleague who’s using Parallels to run windows have seen windows being launched by JNLP on a Mac!!!), and I didn’t found out yet.

I am pretty certain that this is not a java issue but a Parallels (and VMware Fusion) feature. You can assign a filetype to be opened by an app in the VM instead of a native app. So .ini files for instance when double-clicked in Mac OS X will want to open the VM and open it with a windows app.

Hope this helps.

ROCLASI:
I am pretty certain that this is not a java issue but a Parallels (and VMware Fusion) feature. You can assign a filetype to be opened by an app in the VM instead of a native app. So .ini files for instance when double-clicked in Mac OS X will want to open the VM and open it with a windows app.

Hi Robert,

thanks for the precision, but unfortunately I am not that certain, since what you are talking about is file association, but in my case the JNLP files are correctly launching the mac JVM, it’s only when I using inside a jnlp along with another that this happens. It can be Parallels, but that doesn’t mean that JWS has nothing to do about it either.

And, oh, I case you were wondering, I have also tried lots of different syntaxes for os and arch, like os=“Mac”, os=“Mac\ OS\ X” or os=“Mac OS X” and arch=“ppc”, arch=“x86” and arch=“i386” (depending on the libs I wanted to use), since it is not clearly documented what to use and there are many different views about it…
On the mac, once you have that there is the also question of the underlying system you want to use: cocoa or carbon? Depending on the library some say that it’s more compatible to use carbon, some say that cocoa is the way to go, but then there is nothing in the jnlp spec to specify the libs to use… A nightmare, I tell you :{

Hi Patrick,

I know that IT2Be’s browser bean uses native libraries so I checked out it’s jnlp and I see it uses the following syntax:

	<resources os="Linux">
		<jar href="/path/to/linux-stub.jar" download="eager" version="1.0"/>
		<nativelib href="/path/to/native-linux-lib.jar" download="eager" version="1.0"/>
	</resources>
	<resources os="Mac">
		<jar href="/path/to/mac-stub.jar" download="eager" version="1.0"/>
		<nativelib href="/path/to/native-mac-lib.jar" download="eager" version="1.0"/>
	</resources>
	<resources os="Windows">
		<jar href="/path/to/windows-stub.jar" download="eager" version="1.0"/>
		<nativelib href="/path/to/native-win-lib.jar" download="eager" version="1.0"/>
	</resources>
	<resources>
		<jar href="/path/to/shared/code.jar" download="%%loadmethod%%" version="1.0"/>
		etc...
	</resources>

That seems to work but perhaps Marcel can tell you more about it.

Hope this helps.

Thanks Robert,

The JNLP specs are not so precise about the platforms os and arch, in fact it’s up to the system to fill it.
And if you need different resources depending on the arch, it gets worse.
For Mac, there is ppc and i386 and I even seen x86 in some case.

There is also the fact that depending on the Java version, the os string can be interpreted differently (Mac would match “Mac OS X” in certain nodes but not in others), because of that I have add the biggest problems trying to use a node with a jnlp as a resource which in turn uses an node… But that’s another topic.

I also noted that for your jnlp to be recognized by Servoy you need to call it by the name of the jar + .jar.jnlp, for example if you have myplugin.jar, you must have myplugin.jar.jnlp, “myplugin.jnlp” will not be called! Where is the doc about all this???

Thanks for that code Robert, I tried to get the Browser plugin but couldn’t find it anywhere on their website.


To point Java to the right path, I also tried specifying the library path within the JNLP but somehow it does not get applied by Servoy.

I tried to set it up like this to have it load my dylibs on mac:

motorup:

I don’t know the exact path for the mac, but anyway your lib will not be downloaded at this location (imagine that your client will NOT have "Servoy/application_server/ on their hard disk. Whatever is installed by Java Web Start usually goes in the java cache directory…

So check your java properties panel to get the real path of deployement (which depends on the user). For example for me it is in:
“C:/Documents and Settings/ptalbot/Application Data/Sun/Java/Deployment/cache/6.0” and then a folder with a number from 0 to xxx, containing the .jar files (not named .jar though, so it’s a bit difficult to recognize them, but they ARE here).

Then inside 6.0 folder there is also /ext for the files installed by the jnlp installer (that’s where it would download your native libs, basically…)
and there is also a
/host
/muffin (- the cookie folder of the jws system, these Sun guys are soOo funny :) :roll:
/splash and /temp

Have a look and check it on your platform!

I gave up on the setting the property, setting the path doesn’t seem to be very helpful.

Right now my JNLP looks like this:

<?xml version="1.0" encoding="UTF-8"?>

<jnlp spec="1.0+" codebase="%%serverURL%%" href="/servoy-client/plugins/imageutils.jar.jnlp">
   <information> 
      <title>A</title> 
      <vendor>B</vendor>
      <description>D</description>
      <offline-allowed/>
   </information>
   <resources>
      <jar href="/plugins/imageutils.jar" download="eager"/>
   </resources>
   <resources os="Windows">
   	  <jar href="/plugins/imageutils/imageutil-win.jar" download="eager"/>
      <nativelib href="/plugins/imageutils/win.jar" download="eager"/>
   </resources>
   <resources os="Mac">
   	  <jar href="/plugins/imageutils/imageutil-osx.jar" download="eager"/>
      <nativelib href="/plugins/imageutils/osx.jar" download="eager"/>
   </resources>
   <component-desc/>
</jnlp>

All the jars are signed with the same Certificate. The win.jar and osx.jar contain dlls and dylib files.

It seeems to be working on windows but still no way to get it to work on mac os.

If IT2BE made a browser plugin using the same structure and got it to work I must have missed something…

Are the jars correctly downloaded?
Did you verify using the java cache viewer?

If so, what exactly is happening after the download? Any trace of exceptions, server-side or client-side in the console?

The plugin is loaded and I can use it but when I call a function that actually uses a JNI call I get a java.lang.UnsatisfiedLinkError exception.

The library path is: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java

And . seems to be refering to /Applications/Servoy/developer/Servoy.app/Contents/MacOS/. inside the application which obviously isn’t anywhere you’d want to look for a libary.

motorup:
The library path is: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java

And . seems to be refering to /Applications/Servoy/developer/Servoy.app/Contents/MacOS/. inside the application which obviously isn’t anywhere you’d want to look for a libary.

The . can only be “/Applications/Servoy/developer/Servoy.app/Contents/MacOS/” if you are launching your app from developer, not the regular client.
A client will not (at least 99% of the time :)) have the Servoy developer app installed!

The . in that case will probably be the java cache folder. Have a look inside.