I'm proud to announce the second version of Jaiwls today. This version has a direct support for groovy embedded, so you can start writing web application without the need of large IDEs. Now I will show you n this post how you can start up with this new feature. First of all go to the Jaiwls project page and download the newest binary version or do a svn-checkout. If you don't know about Jaiwls, please visit the post Jaiwls Tutorial Part 1: Static Webapplication.
If you try to start the jar, you should see some helping instructions:
~/tmp$ java -jar jaiwls.jar Welcome to JAIWLS 0.02 alpha [options] Usage: java -jar jaiwls.jar [options] obligatory parameters: -port The Port under which your server is reachable. -mainClass The groovy main-class -sourceDirectory The directory where your webapplication-scripts resides optional parameters: -production Don't recompile scripts on every request.
Now it's time to test the included example (you can download it at the end of this post).
~/tmp$ java -jar jaiwls.jar -port 8081 -mainClass WelcomePage -sourceDirectory /home/tschinke/tmp/jaiwls_test_app 2009-03-25 17:35:03.619::INFO: Logging to STDERR via org.mortbay.log.StdErrLog 2009-03-25 17:35:04.185::INFO: jetty-6.1.9 2009-03-25 17:35:04.236::INFO: Started SocketConnector@0.0.0.0:8081 2009-03-25 17:35:04,535 INFO [main] root: Running dynamic JAIWLS-HTTP-Server on Port: 8081, using root: WelcomePage
That's all, now you can start coding directly your webapplication. Note that everytime you do a request, all classes are recompiled and loaded again, so there is no need of restarting the server. And what is more there is a production flag to disable this behaviour and speeding up the whole process.
Please excuse the code of the groovy-example, I'm not yet a groovy expert, so it looks completely like Java.
FAQ
What technique shall I use?
Think deeply about your needs: Perhaps you still need a static application, e.g. if you don't want do deliever your source or you can't integrate a real filesystem access in your application or you need maximum performance.
What's important if I want to migrate from a static to a dynamic application?
Only the ressource allocation stuff has to be changed. You don't need to mark a package with your individual ressources, just use the GGroovyRessource-Class and concate the groovy-package in front of your filename. Example:
getPage().addExternalStyleScript("/"+GGroovyRessource.class.getName()+"/?file=ressources/style.css");
and in your css-file:
background: rgb(255,250,252) url(/de.neotos.jaiwls.framework.widgets.container.GGroovyRessource/?file=ressources/background.png) repeat-x top left;
Or you just use the new mod-rewrite function for this. By default the groovy Ressource handler is automatically mapped to /files/mydata, e.g.
background: url(/file/layout/bglefttop.png) repeat-x top right;
You can find a more complex example, named jaiwls_demo3 in the repository.
Have fun
| Attachment | Size |
|---|---|
| jaiwls_test_app.zip | 32.98 KB |