How to compile Java examples in SDK on Mac

I tried Makefile:

Macbook Pro:Spreadsheet zr$ make
../../../settings/settings.mk:22: /settings/dk.mk: No such file or directory
make: *** No rule to make target `/settings/dk.mk'.  Stop.

Then I manually supplied the path of SDK:

Macbook Pro:Spreadsheet zr$ make OO_SDK_HOME=/Users/zr/Documents/2017.03/LibreOffice5.3_SDK
mkdir -p ../../../MACOSXexample.out/misc/JavaSpreadsheetExamples
"/Users/zr/Documents/2017.03/LibreOffice5.3_SDK/bin/idlc" -C -I. -I../../../idl -O../../../MACOSXexample.out/misc/JavaSpreadsheetExamples XCalcAddins.idl
dyld: Library not loaded: @__VIA_LIBRARY_PATH__/libreglo.dylib
  Referenced from: /Users/zr/Documents/2017.03/LibreOffice5.3_SDK/bin/idlc
  Reason: image not found
make: *** [../../../MACOSXexample.out/misc/JavaSpreadsheetExamples/XCalcAddins.urd] Abort trap: 6

I also tried compiling it in Eclipse, after installing LOEclipse plugin in Eclipse IDE for Eclipse Committers, by following these two links:

And https://github.com/smehrbrodt/libreoffice-starter-extension

(The starter extension does not seem to do anything after I run it.)

I created a new Java Project with the examples/java/Spreadsheet folder in Eclipse, and included all the jars in

/Applications/LibreOffice.app/Contents/Resources/java

Here is the error when I ran the SCal class:

com.sun.star.comp.helper.BootstrapException: no office executable found!
	at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:338)
	at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:302)
	at SCalc.main(SCalc.java:96)

I already set the SDK environment:

MacBook Pro:LibreOffice5.3_SDK zr$ ./setsdkenv_unix 



************************************************************************
 *
 * SDK environment is prepared for MacOSX
 *
 * SDK = /Users/zr/Documents/2017.03/LibreOffice5.3_SDK
 * Office = /Applications/LibreOffice.app
 * Make = /usr/bin
 * Zip = /usr/bin
 * cat = /bin
 * sed = /usr/bin
 * C++ Compiler = /usr/bin
 * Java = /System/Library/Frameworks/JavaVM.framework/Versions/Current
 * SDK Output directory = /Users/zr/LibreOffice5.3_SDK
 * Auto deployment = YES
 *
 ************************************************************************

Did anyone successfully compile any SDK Java examples on Mac? Any instructions or suggestions are appreciated.
I used Spreadsheet example, but any example is fine. Thank you!

Apparently there are some security restrictions in recent macOS which don’t allow you to override DYLD_LIBRARY_PATH.

Saw the same problem in LOEclipse, but didn’t investigate further up to now.

See also Error when creating project on macOS · Issue #54 · LibreOffice/loeclipse · GitHub

Yeah, the hiding-the-DYLD_LIBRARY_PATH misfeature of recent macOS is what bites us there. There is a workaround involving copying bash (or whichever shell you prefer) and make from the system directories to somewhere else, and invoking make with an additional SHELL="$SHELL" argument.
What works for me on macOS 10.13.3 (with Xcode 9.2 command line tools and Oracle’s JDK 9.0.4 installed), with LO 6.0.2 (copied to /Applications/LibreOffice.app) and LO SDK 6.0.2 (copied to ~/Desktop/LibreOffice6.0_SDK) is:

$ mkdir ~/fakebin
$ cp /bin/bash /usr/bin/make ~/fakebin
$ SHELL=~/fakebin/bash Desktop/LibreOffice6.0_SDK/setsdkenv_unix # accepting the defaults:

 ************************************************************************
 *
 *  You have to configure your SDK environment first before you can
 *  use it. The configuration has to be done only once.
 *
 ************************************************************************

sh: line 0: cd: /System/Library/Frameworks/JavaVM.Framework/Versions/CurrentJDK: No such file or directory
 Used SDK = /Users/stephan/Desktop/LibreOffice6.0_SDK

 Enter the Office installation directory [/Applications/LibreOffice.app]: 
 Enter GNU make (3.79.1 or higher) tools directory [/usr/bin]: 
 Enter zip (2.3 or higher) tool directory [/usr/bin]: 
 Enter cat tool directory [/bin]: 
 Enter sed tool directory [/usr/bin]: 
 C++ compilers where for example a language binding exist:
  - Solaris, Sun WorkShop 6 update 1 C++ 5.2 2000/09/11 or higher
  - Linux, GNU C++ compiler, gcc version 4.0.1 or higher
  - MacOS, GNU C++ compiler, gcc version 4.0.1 or higher
 Enter the directory of the C++ compiler, the directory
 where the compiler is located (optional) [/usr/bin]: 
 Enter Java SDK (1.5, recommendation is 1.6 or higher) installation directory  (optional) [/usr]: 
 Default output directory is in your HOME directory.
 Enter an existent directory if you prefer a different output directory (optional) [/Users/stephan]: 
 Automatic deployment of UNO components (YES/NO) [YES]: 

 ************************************************************************
 * ... your SDK environment has been prepared.
 * For each time you want to use this configured SDK environment, you
 * have to run the "setsdkenv_unix" script file!
 * Alternatively can you source one of the scripts
 *   "/Users/stephan/LibreOffice6.0_SDK/gamma.fritz.box/setsdkenv_unix.sh"
 * to get an environment without starting a new shell.
 ************************************************************************


 ************************************************************************
 *
 * SDK environment is prepared for MacOSX
 *
 * SDK = /Users/stephan/Desktop/LibreOffice6.0_SDK
 * Office = /Applications/LibreOffice.app
 * Make = /usr/bin
 * Zip = /usr/bin
 * cat = /bin
 * sed = /usr/bin
 * C++ Compiler = /usr/bin
 * Java = /usr
 * SDK Output directory = /Users/stephan/LibreOffice6.0_SDK
 * Auto deployment = YES
 *
 ************************************************************************
$ cd Desktop/LibreOffice6.0_SDK/examples/java/Spreadsheet
$ ~/fakebin/make SHELL="$SHELL"
mkdir -p /Users/stephan/LibreOffice6.0_SDK/MACOSXexample.out/misc/JavaSpreadsheetExamples
"/Users/stephan/Desktop/LibreOffice6.0_SDK/bin/idlc" -C -I. -I../../../idl -O/Users/stephan/LibreOffice6.0_SDK/MACOSXexample.out/misc/JavaSpreadsheetExamples XCalcAddins.idl
Compiling: XCalcAddins.idl

[…]

--------------------------------------------------------------------------------
Please use the following command to execute the examples!
-
/Applications/Xcode.app/Contents/Developer/usr/bin/make EuroAdaption.run
/Applications/Xcode.app/Contents/Developer/usr/bin/make SCalc.run
/Applications/Xcode.app/Contents/Developer/usr/bin/make ChartTypeChange.run
--------------------------------------------------------------------------------
The Calc add-in component was installed if SDK_AUTO_DEPLOYMENT = YES.
You can use this component inside your office installation, see the example
description. You can also load the "CalcAddins.ods" document to see
how the add-in functions works.
-
/Applications/Xcode.app/Contents/Developer/usr/bin/make CalcAddins.ods.load
--------------------------------------------------------------------------------
$ ~/fakebin/make SHELL="$SHELL" EuroAdaption.run
"/usr/bin/java"  -Dcom.sun.star.lib.loader.unopath="/Applications/LibreOffice.app/Contents/MacOS" -jar /Users/stephan/LibreOffice6.0_SDK/MACOSXexample.out/class/JavaSpreadsheetExamples/EuroAdaption.jar
Connected to a running office ...
Create a new Spreadsheet
Insert example data and use the number format with the currency 'DM'
Change the number format to EUR and divide the values with the factor 1.95583
done