0

I want to add external libraries needed by my project to the custom runtime image.

I use the following external libraries in my project: vlcj.jar, vlcj-javafx.jar

For vlcj.jar to work I also need to add external libraries: jna.jar, jna-platform.jar, vlcj-natives.jar

If I rewrite my application so that I don't need to use vlcj.jar and vlcj-javafx.jar, then the custom runtime image creation line looks like this:

jlink --no-header-files --no-man-pages --compress=2 --strip-debug --module-path 'path/to/javafx-jmods-15.0.1' --add-modules javafx.controls,javafx.web --output /path/to/RuntimeImage

Then I create the jar of my application:

cd path/to/myapp
jar cvfe path/to/myApp.jar MainClass *.*

Then I add myApp.jar to the RuntimeImage and run the app with:

cd path/to/RuntimeImage
path/to/RuntimeImage/bin/java -jar myApp.jar

The application starts up. Things are good.

The only bad thing is that it works without VLCJ. How can I add external VLCJ libraries to the custom runtime image and run my application with it?

Dmitriy
  • 375
  • 1
  • 18

1 Answers1

1

The custom runtime image does not support automatic modules (non-module jars) so you don't have any dependent jars in the jlink image which defines classpath for running with the vlc.

You can edit the META-INF\MANIFEST.MF in your own jar to specify a classpath so the extra jars could be read from the same directory you run java -jar:

Class-Path: vlcj.jar vlcj-javafx.jar jna.jar jna-platform.jar vlcj-natives.jar

Alternatively switch to standard launch for your application with explicit classpath:

path/to/RuntimeImage/bin/java -cp myApp.jar:vlcj.jar:vlcj-javafx.jar:jna.jar:jna-platform.jar:vlcj-natives.jar your.MainClass
DuncG
  • 12,137
  • 2
  • 21
  • 33
  • How do you launch and what is the error? If Class-Path does not specify absolute paths then the those jars must be in the same directory as the pathname specified for myApp.jar parameter, and myApp.jar must exist at that path too. – DuncG Mar 10 '21 at 13:22
  • I found a solution to the problem I wrote about in the deleted comment. It was necessary to add another module to the RuntimeImage. Thanks for the help. Now trying to do this with jpackage – Dmitriy Mar 10 '21 at 19:40
  • Note that JPackage deals with classpath automatically for jars bundled into into your jpackage image (--input imgdir) but will only see modules added by jlink in the bundled JVM runtime image. – DuncG Mar 11 '21 at 18:06
  • How do I then add vlcj jars? I tried adding them using --input path/to/myApp.jarAndVlcjJars. The app launches but VLCJ doesn't work. – Dmitriy Mar 15 '21 at 18:59