1

I am developing an app (Sigar) that will be available for download through a web browser by clicking on a link. The application will monitor machine info, and it needs some library files to do so (such as libsigar-x86-linux.so,libsigar-x86-freebsd-5.so).

My plan is put the native files into a JAR first, then when the application is downloaded with JWS, I will

  • Unpack the JAR file, including the native libraries to a folder
  • Find the current class path as determined when the app is running.
  • Finally set the java.library.path relative to the classpath, so that my native libraries can be found.

Currently I am trying to determine the path for the JAR using this code:

String path = MyClass.class.getProtectionDomain()
   .getCodeSource().getLocation().getPath();

But I must be doing something wrong because the path returned is the web service path, and not one in the local environment.

Could anyone point out what mistakes I have in my current plan? Thanks.

Perception
  • 79,279
  • 19
  • 185
  • 195
Matt
  • 115
  • 1
  • 11

2 Answers2

2

The nativelib tag in the JNLP-file is designed to take care of any native libraries you need.

See the documentation for the resources tag in the JNLP File Syntax.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Also Java is not well suited for wrapping native applications. If all you want is a downloadable Windows application, .NET may be a better choice for wrapper technology. (ClickOnce perhaps?) – Thorbjørn Ravn Andersen Mar 12 '13 at 15:29
0

As mentioned the native lib in jnlp is probably what you are after.

But if for other reasons you want to control the unpacing manually, you could achieve by embedding a jar inside a jar. see: Extract some content from jar-file downloaded with JWS

Community
  • 1
  • 1
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
  • I haven't tested, but I believe that the SecurityManager in place in Java WebStart would not permit trying to load such files as native libraries. – Thorbjørn Ravn Andersen Mar 12 '13 at 15:27
  • ive tried it for bundling and launching an .exe with processbuider, when running the jnlp in unrestricted. but havnt tested loading dlls, so you might be right – Aksel Willgert Mar 12 '13 at 15:40