RSS feed
<< Eclifox | Home | Jetty Does Android - Update >>

Jetty Does Android

Jetty on the Google Android Platform

I've recently been working on porting Jetty to Google's mobile platform called Android.

It's early days still, but I've succeeded in running a minimal setup with a connector (I've tested both bio and nio connectors) and a simple Handler. If you'd like to take a look, then check out the code from the i-jetty project and build it (you'll need to execute the ant build script and then use Android's packaging tool or the Eclipse plugin).

Once you've built and deployed the i-jetty package to the emulator,  find the "Manage Jetty" application, and select the "Start Jetty" button. Then you'll be able to select the Browser application and surf to http://127.0.0.1:8080 and hit the demo "Hello" Handler.

For the moment I've had to do a teeny hack to the servlet api classes, due to this bug in Android, but hopefully that will be fixed soon and I can revert the temporary patches.

Much work remains to be done, but I thought I'd give everyone early warning that this work was going on. Who knows, it might inspire someone to use Jetty to win the Android developer challenge?!
Tags :


Re: Jetty Does Android

Great !

Re: Jetty Does Android

Nice going Jan!

Re: Jetty Does Android

Hi Jan,

Before I found this website I tried to get the embed Jetty into an android app....seems to be having some issues.

Then I saw your posting while researching a solution.

Would you be able to give some direction in making your application work within the emulator?





Re: Jetty Does Android

Hi Mike,

Its very easy  to get the i-jetty project running. All you need to do is:

+ do an svn checkout of the source.
svn checkout http://i-jetty.googlecode.com/svn/trunk/ i-jetty-read-only

+ do an ant build to suck in the jetty modules from the jetty repo:
cd i-jetty-readonly
ant

+ use the Eclipse plugin to build the project (see http://code.google.com/android/intro/installing.html#installingplugin). I haven't used the command line tools to generate the .apk files yet. When I sort out how to do it, I'll post the instructions.

+ once you've got the bin/i-jetty.apk file built, then you just have to run it in an emulator. The Eclipse plugin will install and run the emulator for you. Otherwise, at the command line, you need to do: 
$gwt.home/tools/emulator
$gwt.home/tools/adb install $ijetty.home/bin/i-jetty.apk
As you'll see, the current application that is started by the jetty instance uses a number of specific servlet instances to serve content. I'm working on a more flexible, generic way to serve content, particularly content off the sdcard (see the org.mortbay.i-jetty.servlet.DefaultServlet). Content derived from the various ContentProvider instances is probably always going to require some custom coding.

cheers,
Jan

Re: Jetty Does Android

Hi Jan

I'm trying to get the i-jetty project running but I can't build it inside de Eclipse. I've installed the Ant Plugin and I'm trying to use it but it's not working. As I'm not a late user of Eclipse, problably I'm committing mistakes. The error is the following:

Buildfile: C:\Documents and Settings\User\workspace\i-jetty\build.xml

generate:
        [echo] Generating src-generated
        [copy] Copying 257 files to C:\Documents and Settings\User\workspace\i-jetty\src-generated

BUILD FAILED
C:\Documents and Settings\User\workspace\i-jetty\build.xml:45: java.io.IOException: Cannot run program "patch" (in directory "C:\Documents and Settings\User\workspace\i-jetty\src-generated"): CreateProcess error=2, O sistema não pode encontrar o arquivo especificado

Total time: 1 second

Any tips?

Thanks in advance

Re: Jetty Does Android

Hi Jan

At this moment I've built the i-jetty app. I don't know if I do this right, but now it's occurring the following error (on the emulator) when I try to run the app:

------------------
Application Error: org.mortbay.ijetty
An Error has occured in org.mortbay.ijetty.java.lang.ExceptionInInitializeError.
------------------

In the debug I could that this happens in this line of the IJetty.java, when I click on the Start button:
startService(new Intent(IJetty.this, IJettyService.class), null);

Do you know what's going on?

Thanks in advance!

Re: Jetty Does Android

Hi Luciano,

I believe that I forgot to commit a couple of classes to svn. It should be all checked in now, so do an svn up, rebuild and try it again.

cheers
Jan

Re: Jetty Does Android

1) how can i get the source code of i-jetty  in zip format.
2) can i run web services on i-jetty

Re: Jetty Does Android

i am getting 105 errors in i-jetty code what amy the problem be?

Re: Jetty Does Android

how can i run JSP page on i-jetty?

Re: Jetty Does Android

JSP technology has not been ported to the mobile. JSP is a very file-based technology and most of the environment of android is not.  Moreover, the software architecture of android provides strict separation of visibility of data between applications.

Having said that, android does support the use of an SD card, from which Jetty can already serve files. However, there's a bit of a leap between that and making JSPs work, with their temporary directories, on-the-fly compilation etc etc.

I'd be interested in hearing about what you're doing with Jetty on android, as what folks need/want to do will help shape the future direction that i-jetty takes.

cheers
Jan

Re: Jetty Does Android

Hi Jan

Well, we are interested on Android as a potential platform we would use in our academic work. So, we are testing what already is implemented. In fact, we need a implementation of a SOAP Server on Android, so I ask you if you intend to implement this feature. If not, maybe our team could help to meet this goal. I would appreciate if you contact me by email.

Best regards

Re: Jetty Does Android

I am also getting the error
Application Error: org.mortbay.ijetty
An Error has occured in org.mortbay.ijetty.java.lang.ExceptionInInitializeError.

I checked out a fresh version and still happening.

It looks good

Re: Jetty Does Android

Hi, great to see this happening. We have been developing a web server and related applications for S60 for a while now. I am curious to know how are you going to enable incoming traffic from the Internet? I mean how to get bypass changing IP and firewalls on the cellular network. Or do you plan to have it working only for localhost and a local LAN?

In case you're interested in our S60 web server (based on Apache) it's available at http://mymobilesite.net, and there is a whole lot of developer stuff at http://forum.nokia.com/mws.

Re: Jetty Does Android

Jukka,

if the mobile ISPs block access, then we will be restricted to localhost and phones that have wifi and/or bluetooth.   But for the main app that we are working on (manage contacts, images, etc from a browser), that is probably not a big limitation.

If mobile ISPs are going to allow access to the phones, then I'd only expect limited ports like 80 to be available, so that means a HTTP server makes more sense.  But one would have to consider the application that would make the network costs worthwhile....   while a mobile phone may be a tempting ad-hoc webcam, I'd want that to use wifi rather than g3 :-)

Re: Jetty Does Android

Hi Jan,
    recently, I have ported httpd to android recently. When I saw i-jetty, I guess it's a better choice. After explored the code, I found jsp is not supported,
    Do you mean i-jetty can just support writing servlet?
    Do you have plan to support this?

Thanks & Regards
Huadong

Re: Jetty Does Android

any way
I have sucessfully run the i-jetty on simulator


Huadong

Re: Jetty Does Android

Huadong,

Support for jsps requires jvm support for dynamic class loading. The android platform at the time of writing does not support that. I've tried one of the workarounds that the osgi guys have been using to get the osgi bundles loaded, but I can't seem to get it to work.

I raised a bug for this at the Android issue tracker:
http://code.google.com/p/android/issues/detail?id=439&can=1&q=dynamic&colspec=ID%20Type%20Version%20Security%20Status%20Owner%20Summary

As you can see, dynamic classloading will not be supported for 1.x. Not sure what the reasoning behind that is, but by all means raise a bug or otherwise let the Android devs know that you're interested in such a feature and see if we can shift up the priority.

cheers
Jan

Re: Jetty Does Android

Hi Jan,

  Thanks your comments.

 If dynamic load is enable,

  Do you have some idea about how to make developer develop web application on android phone?

 And google the latest code seams enables the dynamic load. Even they disable the function later, we still have some ways to enable dynamic load java class. So we can develop some wars and download to android phone.

 And now i-jetty removed "start" part to deploye web application automaticly.

  We need give a pattern for developers to develop web application for android phone. Also need a delpoye tool like "start".

 Do you have any good advice?

 Any suggestion is welcome, thankx.

 Regards

Huadong

liuhuadong78@gmail.com

Re: Jetty Does Android

Hi Huadong,

Well, even if dynamic class loading is supported by the jvm, there's still a way to go to make webapplication development easy.  For example, to support jsp on-the-fly compilation, the Dalvik jvm would need to support byte-code-generation, and as I understand it this is also missing.

As that facility is missing, in order to support jsps, you'd need to precompile them, and precompile them for the Dalvik jvm.  So you'd need to mess around with generating the java code using jspc, then run the Dalvik compiler on the generated files. So that just makes webapp dev that bit more difficult.

Leaving aside jsps, and the need to compile your whole webapp with the Dalvik compiler, there's still the issue that there's no way of sharing libraries on the Dalvik platform. So, for example, it would be convenient if you could use the published jetty libs from the i-jetty project rather than having to import the sources into your project and build them.

In the short term, if you want to do webapp development, I'd stay away from jsps, selectively import the jetty sources into your webapp project, and then write a little class with a main to start a jetty server and deploy your webapp (some examples are in the examples/embedded directory of the jetty distro).

If the future, I'd like to write a jetty deployer that would be able to load an Android .apk bundle that contains a webapp from say the sdcard.

regards
Jan

Re: Jetty Does Android

Hi Jan,
    agree, support jsp is a little more difficulty.

    I got one way to develop web application for i-jetty on android by using
    Developer uses eclipse + maven + jetty-maven-plugin to develop web application and servlet. They need make sure the dependence on jetty6.1.9.
    all the servlet will be compiled into a jar file, use dex tool convert the jar file to dex, then zip it as a jar. we can even make the process automatic.
    when make package for web application, put the above servlet jar into webapps's lib dir. After package, we get a WAR file. This file can be installed to android internal web server webapps dir.
     During xmlConfiguration configure the web application, I add a class name MyClassLoader to load those servlet.

MyClassLoader is derived from URLClassLoader and it uses dexFile to open the jar, use WabAppClassLoader as parent classloader.

Regards
Huadong

Re: Jetty Does Android

Hi Jan,
    I can't download the file which size is bigger than 24K when using NIO.
    I have submit an issue
    http://code.google.com/p/i-jetty/issues/detail?id=1

Regards.
Huadong

Add a comment Send a TrackBack