My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
UsageGuide  
how to use java2objc to convert Java code to Objective C
Featured
Updated Oct 16, 2009 by inder123

Introduction

At the moment, there is no standalone java2objc tool that you can run to convert Java code to Objective C. This is because this project is still in progress and is meant for those willing to work with java2objc source-code.

Details

1. Creating a java2objc Eclipse project: Note: java2objc uses maven2.

  • Checkout out all java2objc code svn checkout http://java2objc.googlecode.com/svn/trunk/ java2objc-read-only
  • cd java2objc-read-only/java2objc
  • run mvn eclipse:configure-workspace eclipse:eclipse
  • Start Eclipse and select workspace java2objc-read-only/eclipse-ws

2. Steps to produce Objective C code using java2objc: In the instructions below, I will show how to generate Objective C code for the example Java class examples/examples/AssortedExamples.java

  • First create an eclipse project as describe above in 1
  • Select Run | Run Configuration
  • Choose Main class com.googlecode.java2objc.main.Main
  • Under Arguments, Program Arguments add --outputdir=target examples/examples/AssortedExamples.java
  • Run. This will create target/AssortedExamples.h and target/AssortedExamples.m files that contain the equivalent Objective C for the Java file AssortedExamples.java

Comment by hiqul...@gmail.com, Apr 15, 2010

Can you please provide more details on development environment for trying this out? I'm using Mac and latest eclipse. Not able to get this working. For example, under Run | Run Configuration, I don't see a place I choose com.google.code.java2objc.main.Main.

Was this tested on Linux and using Eclipse ? version

Comment by sandeep....@gmail.com, Jun 21, 2010

Good work Inder.

I have built a binary from the trunk. For the lazy ones who want to run it without much effort, the binaries are bundled here : https://docs.google.com/leaf?id=0B27YZyyr4AC_M2Y1NGVhY2MtNTk3Ni00ODAyLWExMmQtYTQwNjhkYTk5NzU3&hl=en

The output objective C is generated in output folder. Just follow the readme

Good luck.

Comment by project member gilea...@gmail.com, Oct 1, 2010

I've built a binary containing changes I've made to java2objc. It is now much more stable, supports many more language features, and works on folders as well as individual Java files. As with the above binary, follow the readme to use it. You can download it here: https://docs.google.com/leaf?id=0Bw10lZcgyg19NWJkNzNiZTYtYzQ1MS00ZDY3LWE3MGMtYmFiNWQzN2NkMTdl&sort=name&layout=list&num=50

Comment by chris.lu...@gmail.com, Oct 8, 2010

Have you tried compiling the compiler? so to create an objective-C version of your application?

Comment by project member gilea...@gmail.com, Oct 18, 2010

See the third bullet point in the front page: "The generated code is not likely to have the exact same behavior and may not even compile. The generated code is a mere suggestion. A human should look at the generated code and tweak it automatically." Converting this tool to Objective-C would take a lot of additional work on the source code. In addition it depends on the javaparser library which would also have to be converted.

This tool is really meant to give you a head-start for porting code. I used my heavily-modified version above to convert a real world application's code for an iOS port. After conversion the code still needed a fair bit of work to make it compile (mainly related to using Cocoa instead of the Java standard library), and further changes to make it run successfully (mainly related to memory management). The languages are different enough that I think a fully automated conversion tool would be impractical, but this tool can save you a good deal of work.

Comment by avi...@welldocinc.com, Apr 16, 2012

We are using this tool to port POJO to obj-C code. But the major issue that we face is when the Java method returns an Interface. Eg. (ITempInterface)tempMethod is actually to be ported as (id<ITempInterface>)tempMethod but it is ported as (ITempInterface)tempMethod and that causes a lot of issues. Can we by some means detect if a particular guy is an interface and port it accordingly.

Comment by real...@googlemail.com, May 16, 2012

nice work :)

Comment by phiro.k...@gmail.com, Aug 11, 2012

Current codeset no longer runs; After extracting the latest source :

INFO? ------------------------------------------------------------------------ ERROR? BUILD ERROR INFO? ------------------------------------------------------------------------ INFO? One or more required plugin parameters are invalid/missing for 'eclipse:configure-workspace'

0? Inside the definition for plugin 'maven-eclipse-plugin' specify the following:

<configuration>

... <workspace>VALUE</workspace>
</configuration>

-OR-

on the command line, specify: '-Declipse.workspace=VALUE'

INFO? ------------------------------------------------------------------------ INFO? For more information, run Maven with the -e switch INFO? ------------------------------------------------------------------------ INFO? Total time: 25 seconds INFO? Finished at: Sun Aug 12 14:12:22 NZST 2012 INFO? Final Memory: 10M/302M

After run with: ~/apps/apache-maven-2.2.1/bin/mvn eclipse:configure-workspace eclipse:eclipse

OS: Linux (Ubuntu 12.04.2, 64 bits)

Comment by gopeshgu...@gmail.com, Sep 20, 2012

I am continuously getting this error while running the j2Objc Project

"The method getPakage() is undefined for the type CompilationUnit?" CompilationUnitConverter?.java

Powered by Google Project Hosting