iPhoneJava version 0.2.1 released
The new release of iPhoneJava 0.2.1 is now available from maven-central. This release adds some APIs missing in 0.2.0 and fixes several implementation issues. It is mostly API compatible with 0.2.1, so it should be safe to use with existing code.
We are now working on the 0.3.0 release, which is planned to support GWT hosted mode, which means you will be able to debug your Java code running on your device directly from your favorite IDE (eclipse, netbeans, etc.). A new post with additional details will be published soon.
Getting the new release
The new release is now available from maven central. You can include it in your project's maven build by adding the following dependency to your project's pom.xml file:
<dependency> <groupId>org.urish.gwt-titanium</groupId> <artifactId>gwt-titanium</artifactId> <version>0.2.1</version> </dependency> |
Or you can download the JAR file directly from the repository:
iPhoneJava Version 0.2.0 is here !
We are proud to announce the second release of the iPhoneJava project. This release contains a reworked event system which resembles the GWT event system and is much easier to use. Totalling nearly 500 classes, it provides almost complete set of Java wrappers for the Titanium APIs. It is also updated to the latest code from Titanium, and shall support most of the new APIs in Titanium Mobile 1.8.0 which should come out recently.
The focus in this release is the new event system. We are now starting to work on the next major release, 0.3.0, which should contain experimental support for GWT-hosted mode. For those who are not familiar with it, the GWT hosted mode provides a runtime bridge between the Java Virtual Machine (JVM) and the Titanium platform. This bridge allows you to debug the executed code using the JVM's debugger directly from your favorite IDE. Another advantage of the GWT-hosted mode is that the code does not need to be recompiled upon every change - a huge time-saver considering that today you have to compile the Java code using GWT, then the generated Javascript code using the Titanium compiler. We will explain more about the GWT-hosted mode in an upcoming post.
Getting the new release
The new release is now available from maven central. You can include it in your project's maven build by adding the following dependency to your project's pom.xml file:
<dependency> <groupId>org.urish.gwt-titanium</groupId> <artifactId>gwt-titanium</artifactId> <version>0.2.0</version> </dependency> |
Or you can download the JAR file directly from the repository:
Version 0.1.0 released, available on Maven Central
We are proud to announce the first release of the iPhoneJava project. The first release contains Java wrappers for almost all Titanium SDK API's, with over 330 java classes. Some of the wrappers are still incomplete (for example, most event properties still don't have types), however the project is already capable of creating quite impressive apps with the APIs that are there. We still do not consider it ready for the prime time (i.e. app-store release), but it's certainly recommended to download and play with.
The project has been released to maven central. You can include it in your maven build by adding the followingdependency to your project's pom.xml file:
<dependency> <groupId>org.urish.gwt-titanium</groupId> <artifactId>gwt-titanium</artifactId> <version>0.1.0</version> </dependency> |
Or you can download the JAR file directly from the repository:
We are now working on the next release, version 0.2.0. The new version will have an improved event system, and will add type information for many APIs missing from the current version. Stay tuned and write to us!
Hello World example with Maven
We have just uploaded a new "Hello World" example using Maven. The example is freely avaialble on GitHub and can be downloaded from:
https://github.com/urish/iphonejava-hello-world
Screen Shots
Building the example
Since the example project is using Maven, you simply need to extract it and run "mvn install" from the main directory of the project. If you don't have maven installed on your system, can download the latest version from here.
Eclipse users who have installed the Maven plug-in for Eclipse can quickly import this project to their workspace by choosing "Import..." from the File menu, clicking on "Maven" and selecting "Existing Maven Projects". After hitting "Next >" you will be able to choose the directory of your project and click "Finish" to import it into your workspace. Then you can right click on the project and choose "Run As > Maven Install" from the context menu to build the project.
If you use Titanium Studio or Aptana Studio you can also install the Maven plug-in and follow the above instructions. This has been tested and verified to work the the latest version of Titanium Studio.
Running the example
Running the example requires Titainum SDK 1.7.2 to be installed on your system. If you have another version installed, open pom.xml in a text editor and make sure the value of the "titanium.sdk.version" property matches the version you have on your system.
Running it from the commandline is very straightforward: just type `mvn exec:exec` and maven run the project in the iPhone Simluator. If you have the eclipse maven plugin, you can right-click on the project in eclipse, Choose "Run As > Maven build...", and type "exec:exec" (without the quotes) in the Goals box. Then hit the "Run" button to start the example application.
Note that if your copy of the Titanium SDK is not installed in the default location, you will have to change the path in the 'titanium.sdk.home' property inside pom.xml.
Starting your own project
You can use the Hello World example to start your own project. We assume that your project will be called MyProject, and will use the package name "com.mycompany.myproject". Simply clone the source code, and then follow these steps:
Step 1 - Changes to pom.xml
- change the `groupId` to "com.company.myproject"
- change the `artifactId` to "MyProject"
- change the `name` to "My Project"
- change the `iphonejava.package` property to "com.mycompany.myproject"
- change the `iphonejava.module` property to "MyProject"
Step 2 - Changes to src/main/resources/tiapp.xml
- Change the `id` element to "com.mycompany.myproject"
- Change the `name` element to "MyProject"
- Change the `publisher`, `url`, `description`, `copyright` elements as appropriate
- Change the `guid` element to a random GUID value. If you need help getting one, check out this online GUID generator
Step 3 - Create your package under 'src/main/java/com/mycompany/myproject
- Copy HelloWorld.gwt.xml to src/main/java/com/mycompany/myproject/MyProject.gwt.xml
- in MyProject.gwt.xml, change the value of the `rename-to` attribute to "MyProject"
- in MyProject.gwt.xml, change the value of the entry-point `class` attribute to "com.mycompany.myproject.client.MyProjectEntryPoint"
- Create a new class "com.mycompany.myproject.client.MyProjectEntryPoint" (under src/main/java/com/mycompany/project/client/MyProjectEntryPoint.java). The new class should extend the GwtTitaniumBootstrap class (org.urish.gwtit.client.GwtTitaniumBootstrap)
- Override the main() method and write your own code.
That's it! You have just created your own iPhone Java Maven-based project in a few minutes. You may also want to change the application icon and startup screen graphics under 'src/main/resources'.
Running the application on a Real Device
You can run the application on your iOS device by opening it with XCode. After building it and running it inside the simulator (as explained above) you will have a file named "HelloWorld.xcodeproj" under the "target/iphonejava-hello-world-1.0-titanium/build/iphone" directory. Open the file in XCode and you will be able to run the project on your iOS device. You need to be enrolled to the Apple iOS Developer Program, of course.
Help us spread the word !
Like this project? Please help us by spreading the word... Start by clicking the "Like" and +1 buttons below, or by twitting about it (if you have twitter).
We now have events !
We have just added basic wrappers for all the Titanium SDK events, enabling type-safe handling of events in your iPhoneJava projects.
Since the code is automatically generated from Titanium's documentation, and their documentation lacks information about the types of the event properties, most of the properties currently use the Object type. We are going to manually add the type information over time.
This change is a significant step towards making the project useful for production, as event handling is a very important aspect of every user-interface application.
Examples for some of the new event wrappers:
- BatteryEvent - monitors the device's battery level
- ClickEvent - fired when the user taps on a button/widget
- ShakeEvent - detects a "shake" gesture
- VolumeChangeEvent - fired when the user changes the volume of a media player widget
These are just a few examples for the events provided by the Titanium Platform. The new update adds wrapper for all the events supported in Titanium, which totals to 133 different events.
iPhoneJava goes with Maven
You can now build the gwt-titanium module using maven. Just clone (or download) the latest version from our GitHub repository and run the following command:
mvn install
This will build the project and install it to your local maven 2 repository. You can then start using the gwt-titanium module in your own iOS Java projects. If you don't have the "mvn" command installed on your system, you can download it from the Apache Maven downloads page. The project should compile with Maven version 3 (and hopefully also version 2).
iPhoneJava Maven Project Structure
An iPhoneJava Maven project has the following structure:
- src/main/java - Holds all your java classes source code
- src/main/resources - Holds all your projects resources
- src/main/resources/tiapp.xml - Titanium Application Descriptor (see below)
- src/main/assembly/titanium.xml - Describes how to assemble the Titanium project (see below)
- target - This is where the compiled project goes
- pom.xml - Maven build file
Using maven for your own project
You can also take advantage of maven to automatically build, package and run your iOS java application. Just follow the steps below:
Step 1 - Add the gwt-maven-plugin to your pom.xml
Add the following code inside the plugins section of your pom.xml:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gwt-maven-plugin</artifactId> <version>2.3.0-1</version> <executions> <execution> <configuration> <module>org.urish.iphonejava.examples.helloworld.HelloWorld</module> <style>pretty</style> </configuration> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> |
Make sure to replace the 'org.urish.iphonejava.examples.helloworld.HelloWorld' with your own GWT module name. If you wish to use GWT version other than 2.3.0, make sure you change the version number here and also in the dependecies (see step 2).
Step 2 - Add dependencies
Add the following dependencies to your pom.xml:
<dependencies> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-user</artifactId> <version>2.3.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.urish.gwt-titanium</groupId> <artifactId>gwt-titanium</artifactId> <version>0.1.0</version> </dependency> </dependencies> |
Step 3 - Add assembly plugin
The assembly plugin will take your GWT generated code and automatically create a Titanium project from it. First, add the following into the plugins section of your pom.xml:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2.1</version> <configuration> <descriptors> <descriptor>src/assemble/titanium.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> |
Then, create a file named 'titanium.xml' under the 'src/assemble'. This file describes how to put together the Titanium project from the GWT compiled javascript code. The file contents is as follows:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>titanium</id> <formats> <format>dir</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${basedir}/src/main/resources</directory> <outputDirectory>/Resources</outputDirectory> <excludes> <exclude>tiapp.xml</exclude> </excludes> </fileSet> </fileSets> <files> <file> <source>${project.build.directory}/${project.artifactId}- ${project.version}/${project.artifactId}/${project.artifactId}.js</source> <outputDirectory>/Resources</outputDirectory> <destName>app.js</destName> </file> <file> <source>${basedir}/src/main/resources/tiapp.xml</source> <outputDirectory>/</outputDirectory> </file> </files> </assembly> |
Finally, create your tiapp.xml file under the src/main/resources directory. For example:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <ti:app xmlns:ti="http://ti.appcelerator.org"> <deployment-targets> <target device="mobileweb">false</target> <target device="iphone">true</target> <target device="ipad">true</target> <target device="android">true</target> <target device="blackberry">false</target> </deployment-targets> <guid>0abb784b-a5dd-40dd-adff-c829d36d373c</guid> <id>org.urish.iphonejava.examples.helloworld</id> <name>HelloWorld</name> <version>1.0</version> <publisher>Uri Shaked</publisher> <url>http://</url> <description>not specified</description> <copyright>2011 by Uri Shaked</copyright> <icon>appicon.png</icon> <persistent-wifi>false</persistent-wifi> <prerendered-icon>false</prerendered-icon> <statusbar-style>default</statusbar-style> <statusbar-hidden>false</statusbar-hidden> <fullscreen>false</fullscreen> <navbar-hidden>false</navbar-hidden> <analytics>true</analytics> <iphone> <orientations device="iphone"> <orientation>Ti.UI.PORTRAIT</orientation> </orientations> <orientations device="ipad"> <orientation>Ti.UI.PORTRAIT</orientation> <orientation>Ti.UI.UPSIDE_PORTRAIT</orientation> <orientation>Ti.UI.LANDSCAPE_LEFT</orientation> <orientation>Ti.UI.LANDSCAPE_RIGHT</orientation> </orientations> </iphone> <android xmlns:android="http://schemas.android.com/apk/res/android"> </android> <modules> </modules> </ti:app> |
Make sure to customize the following values: guid, id, name, version, publisher, url, description, copyright. The guid parameter should be simply a random GUID.
Step 4 (optional) - Add exec plugin
If you follow this step, you will be able to build and lunch your project in the iPhone Simulator directly from maven. Add the following code under the plugins section of your pom.xml:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1</version> <executions> <execution> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>/Library/Application Support/Titanium/mobilesdk/osx/1.7.2/titanium.py</executable> <workingDirectory>${project.build.directory}/${project.artifactId}-${project.version}-titanium</workingDirectory> <arguments> <argument>run</argument> <argument>--platform=iphone</argument> </arguments> </configuration> </plugin> |
Note that you will have to change the path to the titanium.py script to match the installed version of Titanium SDK on your system.
Give it a go!
Once you have configured your iPhoneJava project to run with maven, run the following command to build it:
mvn package
If you also followed step 4, you will be able to run it directly from maven using the following command:
mvn package exec:exec
Example Project
We are working on creating a complete, working example project with the Apache Maven build system. Once the example project is complete, we will put a download link here.
“Hello World” iPhone Application, written in Java

No development platform is complete without an "Hello World" example. In this post, I am going to give you a simple "Hello World" iPhone application written entirely in Java using the gwt-titanium SDK. The example shows how to create UI controls, add them to screen, add an event listener and display an alert message when a button is clicked.
You can pull the fully working example code from our github repository.
Instuctions how to build the example can be found in our blog post iPhone Java project kicks off.
The Code
public class HelloWorld extends GwtTitaniumBootstrap { @Override public void main() { Window win = UI.createWindow(); win.setBackgroundColor("white"); win.setTitle("Hello, World!"); API.info("Hello World example started"); Label label = UI.createLabel(); label.setColor("blue"); label.setTextAlign("center"); label.setText("Hello World !"); label.addClickHandler(new EventCallback() { @Override public void onEvent(JavaScriptObject event) { AlertDialog alertDialog = UI.createAlertDialog(); alertDialog.setTitle("Example"); alertDialog.setMessage("Hello, World"); alertDialog.show(); } }); win.add(label); win.open(null); } } |
Screen Shots
Clicking the blue "Hello World" label yields the following popup alert message:

iPhone Java project kicks off!
iPhone Java is a new initiative enabling developers to create iPhone applications using the Java programming language. The project takes advantage of existing technologies (namely Google Web Toolkit and Appcelerator's Titanium) in order to enable the creation of native-looking iPhone applications written entirely in Java.
Underlaying Technologies
The Google Web Toolkit (GWT) technology enables seamless and effective compilation of java code into javascript code, and is developed by google. The framework is originially targeted at web developers, but can also be extended to support additional scenarios.
The Appcelerator Titanium SDK is a framework which enables creating native-looking mobile applications for various mobile platforms, including the iOS and Android platforms. The application code is written in javascript, then packaged with a native javascript runtime engine and a set of modules providing access to most of the native device functionality.
iPhone Java (code-named 'gwt-titanium') is a set of Java bindings for the Titanium APIs, along with a custom GWT linker, enabling the compilation of java code into a javascript equivalent that can run directly under the Titanium platform.
Project Status
There is no official release yet, but a significant amount of code has already been comitted to our github repository. There is currently very little documentation, one working 'hello-world' example, initial (non-working) code base for a Kitchen Sink example, and comprehensive javadocs for the API bindings based on Titanium SDK documentation. The code for the project is released under the Apache License, Version 2.0.
'Hello World' Example
The hello world example provides a quick proof of concept and serves as a starting point for new projects. An upcoming blog post will cover the 'Hello World' example in detail, including some screenshots.
Obtaining & Building
Get a fresh copy of the latest source code from github. If you are not familiar with github, you can download a zipped copy by clicking the "Downloads" button on the top-right side of the github page, then you will get a dialog window offering you to download the source code directly.
Next, place the files "gwt-user.jar" and "gwt-dev.jar" from GWT 2.2 distribution under the 'lib' directory. Newer version of GWT will also work. The latest GWT sdk (at the time of writing) can be downloaded here: http://google-web-toolkit.googlecode.com/files/gwt-2.3.0.zip.
Finally, run the "build.xml" file using the ANT build system. This will create a file named "gwt-titanium.jar" under the 'build' directory, which is the GWT module you use for creating iOS applications in Java.
Building 'Hello World'
Simlpy run the "build.xml" ant file in the 'examples/hello-world' directory. This will result in a file called "HelloWorld.js" under 'examples/hello-world/build', which is the javascript compiled version of the example.
Running 'Hello World'
You will need a Mac device for running the 'Hello World' example on your iOS device. If you only have a windows machine, you can still use the framework and utilize the Titanium support for android in order to run the example inside the Android emulator or on a real Android-based device. You will also need the Appcelerator Titanium SDK installed (free, under the Apache 2 License).
Create a new mobile project inside the Titanium Studio IDE. After you have created the project, simply copy and paste all the content from the HelloWorld.js you built in the previous step to 'Resources/app.js' in the newly created project. Run the new application from within the Titanium Studio and you are ready to go!
If you need assistance in installing the Titanium SDK and creating a project, check out Appcelerator's Help Center.
Credits
The iPhone Java project is lead by Uri Shaked.
I would also like to credit the gwt-node project, which provided a great start for creating the custom GWT linker.
Final Words
The gwt-titanium project is just in the beginning. I would love to hear your thoughts and ideas and see how far we can go with this project.


