How to use Xcode for JExternal


This page explains how to use Xcode to create and debug Demo5.jar which is used in JExternal demo JEX_SimpleDemo_411. If you use Xcode to create Java methods to be called from 4D by JExternal, you can debug them while 4D is running. The demo was created by 4D v11. It is included in which is downloadable here.


Demo5.jar in JavaClasses folder is used for 4D structure file "JEX_SimpleDemo_411.4DB".


Demo5.jar has "com.ronri_kobo.demos.Demo5" class. The class has a static method "getSystemProperties ()" which returns all system properties of Java. The Java method is called from 4D as follows:


1. How to create Demo5.jar


[1.1] Launch Xcode which is located in /Developer/Applications. Quit 4D because it will be launched by Xcode later.


[1.2] Run menu item "New Project..." in File menu of Xcode. In "Assistant" window, select "Java Tool" and click "Next" button.


[1.3] In "Assistant" window, set the project name and directory of Demo5, and click "Finish" button.


[1.4] Xcode opens the project window for Demo5.


[1.5] Run menu item "Edit Active Executable 'Java'" in Project menu. In 'Executable "Java" Info' window, replace "/usr/bin/java" with "/Applications/4D v11 SQL/4D Developer Professional/4D" in the Executable path field (assuming that 4D is installed in that directory). When you replace it, the window title changes to 'Executable "4D" Info'. This replacement is important to debug Java code while 4D is running. 4D in that directory is launched by Xcode debugger. Close this window when the replacement ends.


[1.6] Run sub menu item "New Run Script Build Phase" of menu item "New Build Phase" in Project menu. In 'Run Script Phase for "Demo5" Info' window, create a shell script in Script field as follows:


[1.7] The shell script above copies Demo5.jar in Debug folder into JavaClasses folder.


[1.8] When you close 'Run Script Phase for "Demo5" Info' window, a new build phase "Run Scrip" is added in Groups & Files pane of the project window.


[1.9] Double-click "" in Groups & Files pane of the project window to open the source code editor window. In the editor window, modify as follows:


[1.10] To build Demo5.jar from the source code, run menu item "Build" in pop-up menu "Build". When the build is successfully completed, Demo5.jar is created in Debug folder and copied into JavaClasses folder by the shell script ( refer to [1.6] ).


2. How to debug


[2.1] In the editor window, click the left side of the source code to set breakpoints as follows:


[2.2] To start debugging, run menu item "Debug Executable" in pop-up menu "Build and Go". Then 4D in /Applications/4D v11 SQL/4D Developer Professional/ starts, because it is set in Executable path ( refer to [1.5] ). In 4D, run sub menu item "Database..." of menu item "Open" in File menu to select JEX_SimpleDemo_411.4DB structure file.


[2.3] To call the Java method to be debugged, open Demo5 window in JEX_SimpleDemo_411 and click "Get System Properties" button.


[2.4] When the line below is executed in the button script, the current window is switched to the debugger window of Xcode.


[2.5] The execution stops at the breakpoints and you can debug the Java method. When the execution of the Java method ends, the current window is returned to the Demo 5 window of 4D and the result of the Java method is displayed in it.


If you use Xcode, you can debug your Java code by synchronizing with 4D.