I-jetty environments on Android devices-Web servers on your phone

Source: Internet
Author: User

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
    1. public void  Init (servletconfig config)  THROWS SERVLETEXCEPTION  
    2. {  
    3.      Super.init (config);   
    4.     android.content.ContentResolver  resolver =  (Android.content.ContentResolver)  config.getservletcontext (). getattribute (
    5.      android.content.Context androidContext =  (Android.content.Context)   Config.getservletcontext (). getattribute (
    6. }  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.