|
DownloadableWebapps
How to create downloadable webapps.
Featured Creating Downloadable Web ApplicationsMaking a webapp that is dynamically downloadable by i-jetty is very much like making a normal webapp. The only tricky step is that you need to run the dx tool over the classes that would normally be in WEB-INF/classes and the jars that would normally be in WEB-INF/lib. You can see examples of how we do that with maven in the Console web application and the Hello World web application. We do three things specially for Android:
Unpacking the dependencies <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<excludeArtifactIds>servlet-api,android</excludeArtifactIds>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>${project.build.directory}/generated-classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>Using dxWe hook the dx tool into the build of the webapp at the process-classes phase of the maven build lifecycle: <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<!-- Convert the compiled classes into a clases.dex. -->
<execution>
<id>generate-dex</id>
<phase>process-classes</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${env.ANDROID_HOME}/platform-tools/lib/dx.jar</argument>
<argument>--dex</argument>
<argument>--verbose</argument>
<argument>--core-library</argument>
<argument>--output=${project.build.directory}/classes.dex</argument>
<argument>--positions=lines</argument>
<argument>${project.build.directory}/classes/</argument>
<argument>${project.build.directory}/generated-classes/</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>Zipping the classes.dex file <plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>copydex</id>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir
dir="${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/lib" />
<jar
basedir="${project.build.directory}"
update="true"
includes="classes.dex"
destfile="${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/lib/classes.zip" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>Using i-jetty to Download a WebAppNOTE: Android SDK 1.5 and above is needed to support dynamic webapps. After you've prepared your web app - you might like to read the section below on Sample Webapps for some hints - you need to download it to the phone. First, you'll need to arrange for the webapp to be served from a http:// url. The easiest way to do this is to serve it from a Jetty installation on your desktop machine. The Jetty site has full instructions on how to download and install it. Once you've got Jetty installed - and lets assume you installed it to $JETTY_HOME - make a directory called $JETTY_HOME/webapps/downloads. Now copy your android-ready war file to that directory. Start Jetty. Your webapp will now be available as a downloadable file from the url http://[your host ip]/downloads/[your webapp name]. So for example, if your host ip address is 10.10.1.10 and you build a webapp called myfirstwebapp.war, then it is downloadable from http://10.10.1.10/downloads/myfirstwebapp.war. Now, go to your phone or emulator and start i-jetty if its not already running. Select the Download button and type in the url of your webapp. Then enter the context path at which you want that webapp available. For example, you might want to access it as "/howcoolami". i-jetty will now download your webapp and install it to the phone. At the time of writing, you will need to restart i-jetty to get it to deploy your new webapp, although we are working on providing a hot deploy capability. Sample WebAppsThe i-jetty project comes with a couple of example webapps that you can build, and then dynamically download with i-jetty to get you going with the concept of dynamic webapps in the android environment. Hello World ExampleThe "HelloWorld" web application in $I_JETTY_HOME/example-webapps/hello prints out the famous "Hello World" message. The web app contains one very simple Servlet as an example of how to prepare a web app that has classes in addition to static content. The pom.xml for HelloWorld does a couple of things to make the webapp android-ifiable (if I can invent that word):
That's all you need to do for a simple webapp that uses no libraries. For more complex webapps that use 3rd party libs, refer to the "Chat" webapp. Chat ExampleThe "Chat" web application is a much more sophisticated beast than "HelloWorld". It uses 3rd party java libraries, such as the Jetty implementation of the cometd Bayeux protocol, along with the dojox.cometd javascript library to implement the now-classic Ajax chat room. Again, this is essentially a straight-forward webapp, with the only added complication that the 3rd party jars need to be dex-ified. Looking at the pom.xml for the Chat application, you'll see that prior to the 2 steps outlined above in the HelloWorld app, the build first unpacks the classes from the dependency jars. Thus, during the dx step, all classes - both those of the webapp and those from the libraries it uses - are all compiled into the classes.dex and then classes.zip file. Other ExamplesHybridServerPages has a Sample application permanently running on http://www.hybridjava.com:8080/HJ_Sample/, which can be run under i-jetty on Android. It is downloadable via the web or via i-jetty's Download feature from http://www.hybridjava.com:8080/HJ.war. |
I have download hello-2.1.war to i-jetty, could you tell me how to run this war?
in simple English, you need to 1. put hello-2.1.war on a server that your device can access via http://[your host]/[your-path]/hello-2.1.war 2. (double check) test if that server can be accessed from your device from web browser first (I even download it with desktop browser once) 3. from i-jerry main screen go to Download? --> URL? --> enter a URL tested in 2 (http://[your host]/[your-path]/hello-2.1.war) 4. Path? can be any simple name URL style name such as hellosample? (I guess) 5. Click Download? and it should show some "installation complete" kind of message
I am trying to develop a webapp similar to hello world, my webapp works fine on Tomcat, now I want this app to be running on i-jetty server. I am not sure how to add pom.xml and other classes for that. Is there any tutorial for creating a web app for i-jetty.
Thanks
How do I add a webapp that should be installed automatically with the iJetty installation (like the console application)?
Thanks
How do i remove apps from i-jetty on android.
Thanks
I have your answer hbenlulu,
As I wanted to do the same thing. So I figure it out:
first you need to change the pom.xml config file of i-jetty (from /ijetty/trunk/modules/i-jetty/pom.xml that it include in the i-jetty build the war file that you want.
here is a snapshot of pom.xml extra lines to include hello and chat webapp:
....
.....
<configuration> <!-- <classifier>sources</classifier> -->
....
....
that will include your war files in your ijettysnapshot.apk
then you need to change the code of i-jetty Android application to deploy the other war file stored than console.
this code is in: ~/ijetty/trunk/modules/i-jetty/src/org/mortbay/ijetty/IJetty.java
add the following as for console (included here):
....
recompile et Voila!
just add you 2 ijetty .apk into your rootfs directory in system/app/ for real device or in the emulator
that's it!!!
I have an application since before that works fine. But when building for i-jetty I first got an error telling me it could not locate org.apache.log4j. I realized I forgot to dexify the 3rd party libs. So I added those lines in the pom.xml. But now it only says "SERVICE_UNAVAILABLE". Can SERVICE_UNAVAILABLE mean I got an exception somewhere ? How do I access the log-files, if there are any ?
Thanks
eriksson, If you run "adb logcat >log.txt" from command prompt, you would get the log created on Android emulator. It would have the information about the exception occured. Note that log.txt file would be created at the location from where you are running the command. Assuming that you are doing it on Windows platform. For other latform you can look for similar commands.
Thanks
Its driving me crazy. Not getting any information anywhere on i-jetty if it is possible to run JSP webapps. Googling it since last few days. Can someone please help in at least knowing if it is possible? Want to switch to something else to achieve the result because I am not able to resist the temptation of using JSP and at the same time not able to figure out if it is possible and how.
Please someone help. Thanks Arvind
Arvindmaurya1978, I thought I already responded to you? You have to precompile your jsps. From your subsequent posting, it seems that the runtime jsp engine is still required, so you'll need to add in the jasper jars to the i-jetty build. Try adding in a dependency on org.mortbay.jetty.jsp-2.1-jetty.
Jan
Hi!
I install i-jetty on my emulator and it's ok!
I don't understand how create a webapp compatible with i-jetty
"The only tricky step is that you need to run the dx tool over the classes that would normally be in WEB-INF/classes and the jars that would normally be in WEB-INF/lib."
How can I do that??? I have to use Maven?
Thanks
Deborah,
Look at the source code, for the example web applications. Here's a link to browsing the svn repo: http://code.google.com/p/i-jetty/source/browse/#svn/trunk/webapps.
Jan
Hi Jan,
thanks for your replay! I look the code, but is there an IDE or a plug-in for eclipse that generate automaticaly the structure project? I install Meven plug in for eclipse but I don't know if it's usefull.
Regards
Deborah
Hi Jan, Thanks for reply. I did tried earlier and tried again using pre-compiled JSPs. Here is how dependency section of my pom.xml looks however while starting jetty server, I am getting following in the log I/dalvikvm( 204): Failed resolving Lorg/apache/jasper/runtime/JspApplicationContextImpl?; interface 298 'Ljavax/servlet/jsp/JspApplicationContext?;'
W/dalvikvm( 204): Link of class 'Lorg/apache/jasper/runtime/JspApplicationContextImpl?;' failed
I/dalvikvm( 204): Could not find method org.apache.jasper.runtime.JspApplicationContextImpl?.removeJspApplicationContext, referenced from method org.apache.jasper.servlet.JspServlet?.destroy
W/dalvikvm( 204): VFY: unable to resolve static method 3506: Lorg/apache/jasper/runtime/JspApplicationContextImpl?;.removeJspApplicationContext (Ljavax/servlet/ServletContext?;)V
D/dalvikvm( 204): VFY: replacing opcode 0x71 at 0x0016
D/dalvikvm( 204): Making a copy of Lorg/apache/jasper/servlet/JspServlet?;.destroy code (120 bytes)
W/dalvikvm( 204): Unable to resolve superclass of Lorg/apache/jasper/runtime/JspFactoryImpl?; (302)
W/dalvikvm( 204): Link of class 'Lorg/apache/jasper/runtime/JspFactoryImpl?;' failed
E/dalvikvm( 204): Could not find class 'org.apache.jasper.runtime.JspFactoryImpl?', referenced from method org.apache.jasper.compiler.JspRuntimeContext?.<clinit>
W/dalvikvm( 204): VFY: unable to resolve new-instance 510 (Lorg/apache/jasper/runtime/JspFactoryImpl?;) in Lorg/apache/jasper/compiler/JspRuntimeContext?;
D/dalvikvm( 204): VFY: replacing opcode 0x22 at 0x0008
D/dalvikvm( 204): Making a copy of Lorg/apache/jasper/compiler/JspRuntimeContext?;.<clinit> code (526 bytes)
W/dalvikvm( 204): Exception Ljava/lang/NoClassDefFoundError?; thrown during Lorg/apache/jasper/compiler/JspRuntimeContext?;.<clinit>
W/Jetty ( 204): failed jsp: java.lang.ExceptionInInitializerError?
D/dalvikvm( 204): GC freed 6963 objects / 523704 bytes in 185ms
I/dalvikvm( 204): Failed resolving Lorg/apache/jasper/runtime/HttpJspBase?; interface 297 'Ljavax/servlet/jsp/HttpJspPage?;'
W/dalvikvm( 204): Link of class 'Lorg/apache/jasper/runtime/HttpJspBase?;' failed
I have verified in generated-classes folder for the existence of the classes being complained here. Also, looked at the class file and verified that method like removeJspApplicationContext does exit in the the class JspApplicationContextImpl?. Not sure then why it is complaining. Please let me know if doing something wrong. Appreciate your help.
A question drives me crazy: In my webapp I want to use a third party dependency, which need to load a properties file. the code such as loadProperties("/xxx.properties"); I don't know where to put the file. It seems the generated classes.dex file cannot find the file in my dependency jar file. What the path of properties file should I set in loadProperties method? Hope someone can help!!!Please!!!
Hi lulubaobao, in my webapp i have to load a file. When maven create a .war file don't include the file that I want to load, so I add manually this file to .war file generated by maven. Then I read the file simply in the following way:
I hope it helps :)
deborah
Hi, I have a query. Can I access console app from multiple machines simulatenously?
Thanks Arvind
Hiiii!
After the Download of my webapp. I should to restart i-jetty to get it to deploy my new webapp,but when I restart i-jetty, i-jetty not start again! Have you any idea? Thanks
Hi everyone,
How do you debug the java part (i.e. HttpServlet?) of i-jetty webapps in Eclipse? I read through the comments and don't have a good idea how to approach this. Thanks so much!
First of all, thanks for the great work. I really like it.
After playing with i-jetty for a while, one thing that I wanted was a feature to install my webapps from the local file system of Android, so that I don't have to setup a web server externally.
After looking at the code, it turned out that it was not that difficult to do.
Here is the svn diff output (against revision 396) for the code changes that worked for me. With these changes, I can do something like the following to install my webapps.
Index: i-jetty-ui/src/org/mortbay/ijetty/IJettyDownloader.java =================================================================== --- i-jetty-ui/src/org/mortbay/ijetty/IJettyDownloader.java (revision 396) +++ i-jetty-ui/src/org/mortbay/ijetty/IJettyDownloader.java (working copy) @@ -18,6 +18,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.net.URI; import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.http.HttpStatus; @@ -144,7 +145,13 @@ text = (EditText)findViewById(R.id.context_path); String path = text.getText().toString(); - startDownload(url, path); + if (url.startsWith("http:")) { + startDownloadInstall(url, path); + } else if (url.startsWith("file:")) { + startInstall(url, path); + } else { + Log.e("Jetty", "Unknown url " + url); + } } } ); @@ -221,10 +228,30 @@ } /** - * Begin a download of a war file. + * Begin an install of a war file. * @param url + * @param path */ - public void startDownload (final String url, final String path) + public void startInstall (final String url, final String path) { + try { + File warFile = new File(new URI(url)); + if (!warFile.exists()) { + Log.e("Jetty", "File does not exist "+url); + return; + } + install(warFile, path); + } catch (Exception e) { + Log.e("Jetty", "Error installing file "+url, e); + return; + } + } + + /** + * Begin a download and install of a war file. + * @param url + * @param path + */ + public void startDownloadInstall (final String url, final String path) { final String war = getWarFileName (url); final File warFile = new File (tmpDir, war);Hi I have developed a simple webApp with Eclipse. I had run dx command on the .class and the output is on the /lib/classes.zip. Then I have generate the war file whit jar command. Finally I have download this webApp on i-jetty but don't work... Why??
Hi all,
I have a couple of apps in the webapps directory of jetty on Android. One is called books the other picture. When I run the server I noticed that the 127.0.0.1:8080 does not give the default ijetty page but rather the books app page ... sometimes it won't even do that and it will tell me ERROR 404 Not Found No context on this server matched or handled by this request! If I include the full context path to the app (127.0.0.1:8080/books-2.2.SNAPSHOT.war/ it fails giving the service is unavailable. What is going on?
Thanks
Hi ALL,
I am trying to download a simple webapplication on the i-jetty server. And I am getting some kind of class loading exception which i am not aware of. Any help would be highly appreciated.
Following are the key points :
I am using third party jar (apache commons fileupload and apache commons io). Third party jars are dex-ified Decompiled classes.dex and verified that dex'ed third party jars are present. I get the errors when the app is deployed on the server.
See below for my POM.xml and Stacktrace.
-----------------------------------------------POM.XML--------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <project
</dependency> </dependency>
</project>-------------------------------------LOG----------------------------------------------------------
9-07 16:39:08.279: INFO/dalvikvm(30351): DexOpt??: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlSerializer??;' 09-07 16:39:08.284: INFO/dalvikvm(30351): DexOpt??: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser??;'
09-07 16:39:08.489: DEBUG/dalvikvm(29530): DexOpt??: --- END 'classes.zip' (success) --- 09-07 16:39:08.489: DEBUG/dalvikvm(29530): DEX prep '/sdcard/jetty/webapps/yesitis/WEB-INF/lib/classes.zip': unzip in 54ms, rewrite 897ms 09-07 16:39:08.494: INFO/Jetty(29530): NO JSP Support for {}, did not find {} 09-07 16:39:08.549: INFO/Jetty(29530): started {} 09-07 16:39:08.554: WARN/dalvikvm(29530): (Lorg/mortbay/ijetty/hello/HelloWorld??; had used a different Ljavax/servlet/http/HttpServlet??; during pre-verification) 09-07 16:39:08.554: WARN/dalvikvm(29530): Unable to resolve superclass of Lorg/mortbay/ijetty/hello/HelloWorld??; (280) 09-07 16:39:08.554: WARN/dalvikvm(29530): Link of class 'Lorg/mortbay/ijetty/hello/HelloWorld??;' failed 09-07 16:39:08.554: WARN/Jetty(29530): FAILED andwebap: java.lang.IllegalAccessError??: Class ref in pre-verified class resolved to unexpected implementation 09-07 16:39:08.554: WARN/Jetty(29530): FAILED o.e.j.w.WebAppContext??{/yesitis,file:/sdcard/jetty/webapps/yesitis/},/sdcard/jetty/webapps/yesitis: java.lang.IllegalAccessError??: Class ref in pre-verified class resolved to unexpected implementation 09-07 16:39:08.564: ERROR/Jetty(29530): EXCEPTION 09-07 16:39:08.564: ERROR/Jetty(29530): java.lang.IllegalAccessError??: Class ref in pre-verified class resolved to unexpected implementation 09-07 16:39:08.564: ERROR/Jetty(29530): at dalvik.system.DexFile??.defineClass(Native Method) 09-07 16:39:08.564: ERROR/Jetty(29530): at dalvik.system.DexFile??.loadClassBinaryName(DexFile??.java:209) 09-07 16:39:08.564: ERROR/Jetty(29530): at dalvik.system.DexFile??.loadClass(DexFile??.java:198) 09-07 16:39:08.564: ERROR/Jetty(29530): at dalvik.system.DexClassLoader??.findClass(DexClassLoader??.java:247) 09-07 16:39:08.564: ERROR/Jetty(29530): at java.lang.ClassLoader??.loadClass(ClassLoader??.java:573) 09-07 16:39:08.564: ERROR/Jetty(29530): at java.lang.ClassLoader??.loadClass(ClassLoader??.java:532) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.mortbay.ijetty.webapp.AndroidClassLoader??.loadClass(AndroidClassLoader??.java:268) 09-07 16:39:08.564: ERROR/Jetty(29530): at java.lang.ClassLoader??.loadClass(ClassLoader??.java:532) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.util.Loader.loadClass(Loader.java:92) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.util.Loader.loadClass(Loader.java:71) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.servlet.Holder.doStart(Holder.java:81) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.servlet.ServletHolder??.doStart(ServletHolder??.java:239) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.util.component.AbstractLifeCycle??.start(AbstractLifeCycle??.java:58) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.servlet.ServletHandler??.initialize(ServletHandler??.java:765) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.servlet.ServletContextHandler??.startContext(ServletContextHandler??.java:245) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.webapp.WebAppContext??.startContext(WebAppContext??.java:1209) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.server.handler.ContextHandler??.doStart(ContextHandler??.java:586) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.util.component.AbstractLifeCycle??.start(AbstractLifeCycle??.java:58) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.mortbay.ijetty.deployer.AndroidContextDeployer??.deploy(AndroidContextDeployer??.java:128) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.mortbay.ijetty.deployer.AndroidContextDeployer??$ScannerListener??.fileAdded(AndroidContextDeployer??.java:36) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:601) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:531) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.util.Scanner.scan(Scanner.java:394) 09-07 16:39:08.564: ERROR/Jetty(29530): at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:345) 09-07 16:39:08.564: ERROR/Jetty(29530): at java.util.Timer$TimerImpl??.run(Timer.java:290) 09-07 16:39:08.569: WARN/Jetty(29530): ContextDeployer??$Scanner failed on '/sdcard/jetty/contexts/yesitis.xmlThanks, A
The Core of my above question is that I am getting "illegal access error" because of some of my dependencies which I have used in my Web Application.
So after searching about it a little bit I found that I should change the scope of the dependencies to "provided" so that it doesn't get added to the WEB-INF folder.
That didnt work as well.
If anybody has a solution or thinks where I could be wrong , please help.
Do I need to do anything special to run a javascript file and a flash file?
I have a program that converts powerpoint into a flash file. The program creates 3 files: a javascript file, an html file, and a flash file. However, when I try to launch it, it shows a little box with a question mark, like it can't run the flash file or something.
Do I need to package the javascript or flash file in some special way?
Thanks, Mike
MichaelC,
The javascript should be fine. AFAIK, Flash is only supported by the android web browser from 2.2 onwards.
Jan
Reminder to everyone that has a question:
please post it to the Jetty discussion group at:
user@jetty.codehaus.org
rather than add comments to this wiki page.
Thanks, Jan
Hi All,
I have deployed a web app in jetty server..while downloading from i-jetty i'm getting download failed with some status code..
can anyone help me to solve issue and tell me where i'm going wrong?
Thanks in advance..