This content has been marked as final. Show 6 replies
You are obviously not setting up LD_LIBRARY_PATH in ProcessBuilder correctly but without seeing the code I can't be more specific.
My console dumps (with some added comments). The environment variables seems to be set correctly.
### DUMP from JAVA application with generated temp folder -> comments in brackets  added to dump
TVDS_TMP_DIR=/tmp/tvds1895770185265633201 [GENERATED and set by process builder]
LD_LIBRARY_PATH=/tmp/tvds1895770185265633201/native-libs [used System.getEnv("LD_LIBRARY_PATH")]
INFO: Loading /tmp/tvds1895770185265633201/native-libs/libMSPdtcc.so [not needed to load]
INFO: Loading /tmp/tvds1895770185265633201/native-libs/libMSPCoordinateConversionService.so [not needed to load]
INFO: Loading /tmp/tvds1895770185265633201/native-libs/libjnimsp_ccs.so [dependencies are libMSPdtcc.so & libMSPCoordinateConversionService.so]
Caused by: java.lang.UnsatisfiedLinkError: /tmp/tvds1895770185265633201/native-libs/libjnimsp_ccs.so: libMSPdtcc.so: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
... 31 more
### DUMP from JAVA application with hardcoded temp folder (files already available from previous run)
INFO: Loading /tmp/tvds1895770185265633201/native-libs/libMSPdtcc.so
INFO: Loading /tmp/tvds1895770185265633201/native-libs/libMSPCoordinateConversionService.so
INFO: Loading /tmp/tvds1895770185265633201/native-libs/libjnimsp_ccs.so
Sorry but I see no Java code so I cannot compare with my working code to see what is different!
I do something like this with the ProcessBuilder (code is a little bit more complex because I add also some VM flags like -Xmx that are read from a config file)
String projectTmpLocation = createTempDir(); ProcessBuilder processBuilder = new ProcessBuilder(JAVA_CMD, "-cp", CLASSPATH); processBuilder.inheritIO(); Map<String, String> environment = processBuilder.environment(); environment.put("TVDS_TMP_DIR", projectTmpLocation); environment.put("LD_LIBRARY_PATH", projectTmpLocation + File.separator + "native-libs"); List<String> commandList = processBuilder.command(); commandList.add(Application.class.getName()); processBuilder.start();
I found a solution for my problem. The directory of the native libs should be created before the ProcessBuilder.start() (new process) is called.
In the old situation I only set the LD_LIBRARY_PATH to something like /tmp/tvds324632879/native-libs and the real application create the director. When I create the /tmp/tvds324632879/native-libs in my bootloader, native libs loading will be successfull.
Thanks for posting your solution. I have just created a self contained test harness that worked every time BUT it just happens to make sure the temp directory exists and copies all the files into the directory before doing anything with ProcessBuilder! It never occurred to me to do it the other way round since the start() method executes the chained program!