This article is mainly to share with you how to make an Android device into a Web server to use.
Compiling I-jetty
1, the source download down, http://code.google.com/p/i-jetty/downloads/list
2, unzip the file, enter the Pom.xml directory, execute the command: Mvncleaninstall, reference (http://code.google.com/p/i-jetty/wiki/BuildInstructions)
During the execution, an exception occurred that caused the memory overflow when generating classes.dex, and we solved it with eclipse.
3, the creation of I-jetty Android project, will download the I-jetty source code covered in,
4. Introduce the jar in the following directory into the I-jetty project:
C:\DocumentsandSettings\troyz\.m2\repository\org\eclipse\jetty
also need to Servlet-api-2.5.jar.
5. Compile and install the I-jetty into the device.
Publish the Web project to the device. Reference (HTTP://CODE.GOOGLE.COM/P/I-JETTY/WIKI/DOWNLOADABLEWEBAPPS)
Because the Java virtual machine on Android cannot directly interpret the. class file, you first need to convert the. class file and the. jar file in the Web project into a. dex file that is recognized by the virtual function .
This assumes that the directory of the Web project is in: E:\demo.
1, need to web-inf/classes directory and Lib directory files, with dx command processing into classes.dex and put into the Lib directory.
Dx.bat--dex--output=e:\demo\web-inf\lib\classes.zipe:\demo\web-inf\classese:\demo\web-inf\lib
2. Fight into a war bag.
CD E:\demo
Jar-cvfdemo.war*.*
3. After generating Classes.zip, you can delete the original. Class and. Jar.
4, through the I-jetty download function, the war download to the device, you can also directly put Demo.war into the/sdcard/jetty/webapps/directory.
5, start the I-jetty server.
I-jetty support for JSP temporarily seems imperfect, perhaps I did not find a good way to HTML is supported, including the HTML JS, support servlet.
Androidtablet (sdk3.0), I-jetty class loader cannot dynamically extract the load Classes.zip, reported the following exception:
DALVIKVM (22984): Can ' Topendexcache '/data/dalvik-cache/[email protected]@[email protected]@[email protected]@[email Protected] ': nosuchfileordirectory
The reason is that the/data/dalvik-cache directory is not writable.
http://code.google.com/p/android/issues/detail?id=966
There is a solution: When you package an Android project, put Java files and jar files from your Web project together in your Android project, so you don't let I-jetty load the Dex file dynamically. The Classes.zip,jar,.class file is not required in the war package. However, this scenario has one drawback: you cannot dynamically deploy a new war package.
6. If you want to use Android's context in a Web application, you need to do this:
Java code
- public void Init (servletconfig config) THROWS SERVLETEXCEPTION  
- {
- Super.init (config);
- android.content.ContentResolver resolver = (Android.content.ContentResolver) config.getservletcontext (). getattribute (
- android.content.Context androidContext = (Android.content.Context) Config.getservletcontext (). getattribute (
- }