Page 1 of 1

Java rpath problem

PostPosted: Sat Nov 03, 2018 10:42 am
by riknik
Since upgrading the MacOS to 10.13.6 I had to update ForexConnect (I chose 1.5 stable build), but then my Java program wouldn't run because I kept getting loader errors that it couldn't find the @rpath relative dynamic libraries. I fixed that by moving all the dylib files it complained about down into the same folder as fxcore2.jar. But what is the correct way to do this, because I shouldn't have to be moving dylib files around.

I'm using Eclipse to build my jar file, and it includes the dylib files in the jar, so Eclipse finds everything correctly. Is there some classpath or other runtime parameter I need to pass to Java in order for @rpath to be set to find the dylibs as they were distributed? I'm hoping if I can set that to resolve the loader issue, I will no longer need to include the dylib files in my jar, that would be a bonus.

Thanks,
Rik

Re: Java rpath problem

PostPosted: Thu Nov 15, 2018 11:34 am
by JuliaS
Hi Rik,

There are two ways for working with ForexConnect in Eclipse:

    1. Create lib folder in the Eclipse project directory and copy content of the ForexConnectAPI-1.5.0-Darwin-x86_64/lib and ForexConnectAPI-1.5.0-Darwin-x86_64/lib/java to the folder.
    2. Update content of the Package Explorer.
    3. Add the fxcore2.jar to build path.
    4. Specify the lib folder as Native Library Location: right click on fxcore2.jar -> Build Path -> Configure Build Path -> Java Build Path -> Libraries -> JRE System Library -> Native Library Location -> specify path to the lib folder.

Or, If you want to keep the same layout as in the ForexConnectAPI-1.5.0-Darwin-x86_64/lib folder:
    1. Create lib folder in the Eclipse project directory and copy content of the ForexConnectAPI-1.5.0-Darwin-x86_64/lib to the folder.
    2. Update content of the Package Explorer.
    3. Add the fxcore2.jar to build path.
    4. In Run Configuration -> Arguments add -Djava.library.path=.:./java.
    5. In Run Configuration -> Working Directory -> Other type ${workspace_loc:Test/lib}.

fxcore2.jar uses all the dylib (fxcore2.jar is just a wrapper around them), so if you do not include the dylib in your jar, you will need to distribute the dylib with your jar.
If you do not want to include dylib in your jar uncheck them in the Export window.

@rapth defined as '.' and '..' for the libfxcore2.dylib and as '.' for other libraries. Path calculated from the JVM working directory.
So, the easiest way would be distribute your application with the content of the ForexConnectAPI-1.5.0-Darwin-x86_64/lib and ForexConnectAPI-1.5.0-Darwin-x86_64/lib/java to the directory where your JAR is located.

Re: Java rpath problem

PostPosted: Sun Nov 18, 2018 9:23 pm
by riknik
what a great reply! You really covered it, thanks!