j2objc0.9.5 using J2OBJC in two--xcode

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.