Build the I-jetty environment on Android devices-web servers on mobile phones, androidi-jetty
This article mainly shares with you how to build an Android device into a web server.
Compile I-jetty
1. download the source code, http://code.google.com/p/i-jetty/downloads/list
2. decompress the file, enter the directory where pom. xml is located, and execute the command: mvncleaninstall, refer to (http://code.google.com/p/i-jetty/wiki/BuildInstructions)
An exception occurs during execution, causing a failure. It is the problem of memory overflow when classes. dex is generated. Let's use Eclipse to solve it.
3. Create an I-jetty android project and overwrite the downloaded I-jetty source code,
4. Introduce the jar files in the following directory to the I-jetty project:
C: \ DocumentsandSettings \ troyz \. m2 \ repository \ org \ eclipse \ jetty
Servlet-api-2.5.jar is also required.
5. Compile and install I-jetty to the device.
Publish a web project to a device. Reference (http://code.google.com/p/i-jetty/wiki/DownloadableWebapps)
Because the Java Virtual Machine on android cannot directly explain the execution of the. class fileFirst, you need to convert the. class file and. jar file in the web project into a. dex file that the virtual machine can recognize..
Assume that the directory of the web project is E: \ demo.
1, the need to WEB-INF/classes directory and lib directory files, with dx command into classes. dex and put the lib directory.
Dx. bat -- dex -- output = E: \ demo \ WEB-INF \ lib \ classes.zip E: \ demo \ WEB-INF \ classesE: \ demo \ WEB-INF \ lib
2. Pack it into a war package.
Cd E: \ demo
Jar-cvfdemo.war *.*
3. After classes.zip is generated, you can delete the original. class and. jar files.
4. Use the download function of I-jetty to download the war to the device. You can also directly put the demo. war in the/sdcard/jetty/webapps/directory.
5. Start the I-jetty server.
I-jetty's support for jsp seems to be not perfect for the moment. Maybe I have not found a good way to support html, including js in html and servlet.
On androidtablet(sdk3.0133, The i-jetty classes.zip reports the following exception:
Dalvikvm (22984): Can 'topendexcac'/data/dalvik-cache/mnt@sdcard@JettyContext217761537@webinf@WEB-INF@lib@classes.zip @ classes. dex ': Nosuchfileordirectory
The reason is that the/data/dalvik-cache directory cannot be written.
Http://code.google.com/p/android/issues/detail? Id = 966
There is a solution: When packaging an android project, place the java and jar files in the web project in the android project for packaging, so that I-jetty cannot dynamically load the dex file. The classes.zip, jar, and. class files are not included in the warehouse. However, this solution has one disadvantage: the new war package cannot be dynamically deployed.
6. If you want to use the android Context in a Web program, you need to do the following:
Java code
- Public void init (ServletConfig config) throws ServletException
- {
- Super. init (config );
- Android. content. ContentResolver resolver = (android. content. ContentResolver) config. getServletContext (). getAttribute ("org. mortbay. ijetty. contentResolver ");
- Android. content. Context androidContext = (android. content. Context) config. getServletContext (). getAttribute ("org. mortbay. ijetty. context ");
- }
How can I install a web server on an android phone? Urgent
Use I-Jetty. Free web service software.
How can I build a web server on the android platform?
Jetty is totally acceptable!