Maven JNA macOS and LD_LIBRARY_PATH
When running Java applications on a *nix
style of operating system that need to load native libraries, you will need to set the LD_LIBRARY_PATH environment variable (or something similar). That's not an issue on Linux.
macOS: I won't let you, it's for your own good
On macOS the System Integrity Protection (SIP) prevents these variables to be set in your shell (bash, zsh). It works inside Eclipse, when you define environment parameters, but not in any shell script. Unfortunately Maven's command line mvn
is a shell script.
The Notes challenge
Since the Notes client is a cross-platform product, the library locations aren't where a macOS program would look for:
- The application directory. That's where the Java runtime is at home, not the notes executable
- In a library location, here looking for
notes
instead oflibnotes.dylib
/Users/[YOURNAME]/Library/Frameworks/notes.framework/
/Library/Frameworks/notes.framework/
/System/Library/Frameworks/notes.framework/
You could try to symlink the first library: ln -s /Applications/HCL\ Notes.app/Contents/MacOS/libnotes.dylib ~/Library/Frameworks/notes.framework/notes
(after creating the rewuired directories) to run into the next challenge.
The Notes libraries are linked at build time with the @executable_path
annotation. Even when linking all libraries into notes.framework
, loading will fail. Maybe in a future version linking with @loader_path
or @rpath
might solve this.
symlink to the rescue
The old joke goes When man doesn't come to the mountain, the mountain will come to man, also known as avalanche (Not to be confuse with the real saying).
Our executable directory is the JDK's (to be able to compile) home, which luckily doesn't contain any dylib
files. With a little loop I give you mvnx
(to be stored in ~/bin
):
#!/bin/bash
# Dynamic linking of Notes libraries into the JDK
JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8-openj9.jdk/Contents/Home
for onelib in $(ls /Applications/HCL\ Notes.app/Contents/MacOS)
do
echo "Linking /Applications/HCL\ Notes.app/Contents/MacOS/${onelib}"
sudo ln -s /Applications/HCL\ Notes.app/Contents/MacOS/${onelib} ${JAVA_HOME}/jre/bin/${onelib}
done
# Actual maven execution
mvn "$@"
# Cleanup
for onelib in $(ls /Applications/HCL\ Notes.app/Contents/MacOS)
do
echo "Unlinking /Applications/HCL\ Notes.app/Contents/MacOS/${onelib}"
sudo rm ${JAVA_HOME}/jre/bin/${onelib}
done
As usual YMMV
Posted by Stephan H Wissel on 12 January 2022 | Comments (0) | categories: Domino Java Maven