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:

