There are two ways of using J2OBJC in Xcode: External build and Xcode build Rule.
Xcode Build Rules mode:
First, create a new project
Open Xcode and choose New Project-Choose a application, such as single View application.
Product name and organization name are optional. My project is named Java2objctest.
Second, add J2OBJC Build Rule
1. Create a new Settings.xcconfig file with the following contents:
J2objc_home = ${j2objc_install_dir}/= $ (inherited) "${j2objc_home}/include" "${derived_files_dir}" = $ (inherited) "${j2objc_home}/lib"= $ (inherited)-L "Z"-L "Jre_emul"-L "Icucore";
The j2objc_home is set to the Dist directory compiled by J2OBJC.
2. Use this file as a compiled configuration:
Both the project--project--info,debug and release are set to this configuration file.
3. Add Custom Build Rule:
Engineering-Engineering Target--build Rules, click the plus sign to create a new rule.
Process Select Java source files
Using the custom script, enter in the following input box:
if [!-F "${J2OBJC_HOME}/J2OBJC"]; Then echo "J2objc_home not correctly defined in Settings.xcconfig, currently set to ' ${j2objc_home} '"; Exit 1; fi;" ${J2OBJC_HOME}/J2OBJC "-D ${derived_files_dir}-sourcepath" ${project_dir}/classes "--no-Package- Directories--prefix othello.engine=oe-g ${input_file_path};
In output files, click the plus sign to add two lines:
${derived_files_dir}/${input_file_base}.h${derived_files_dir}/${input_file_base}.m
The result should be this:
4. Adding Java code and dependent libraries
Create a new Java source folder in the project and add Java code to it, such as I added Skylead/sign/signtool.java in TESTJ2OBJC.
The code is as follows:
Package skylead.sign; Public class SignTool { publicstatic string getsign (String sign) { = ' sign is: ' + sign; return result;} }
Introduce the header file where you need to call this method:
#import "SignTool.h"
You can then use the static methods provided by this class:
nsstring* test = [Skyleadsignsigntool getsignwithnsstring:@ "my Sign"];
Test returns the result: Sign Is:my sign
j2objc0.9.5 using J2OBJC in two--xcode