mercredi avr. 28, 2010

WEB-INF/lib/{\*.jar}/META-INF/resources

This blog has moved to alexismp.wordpress.com
Follow the link for the most up-to-date version of this blog entry.

Modularity is one of the themes for Java EE 6 and servlet 3.0 fragments one often mentioned as one examples of this (see details here). This blog entry is about a small yet very useful new feature of the servlet 3.0 specification to deal with static content such as images, CSS or JavaScript.

Before servlet 3.0, images could be made accessible from the root of the web applications but that meant copying the files to the WAR archive and keeping them up-to-date. This certainly meant a solution tightly coupled with the web application development and packaging. The other option was to place this static content in the docroot of the application server which was in turn time probably too loosely coupled allowing for anyone to access this and encouraging every application to use the same set of static content.

With Servlet 3.0, a JAR placed in WEB-INF/lib has static content from its META-INF/resource directory accessible from the web-context root. You can also parse this previous statement with WEB-INF/lib/{\*.jar}/META-INF/resources. So this means you no longer need to use the ServletContext getResource() and getResourceAsStream() methods with some rather dumb rewriting.

In this simple web application WAR example :

... the static resources are available from :

http://host:port/webcontext/scripts.js
http://host:port/webcontext/styles.css
http://host:port/webcontext/welcome.png


where http://host:port/webcontext/ could be replaced with the relative path "./"

This makes for more modular applications. Other than images, think of how this applies to CSS and javascript. It's probably now a good idea to package JavaScript libraries such a jquery or dojo in a dedicated JAR (effectively a resource JAR).

The other use-case I can think of is configuration files. One could deploy with WEB-INF/lib/testing.jar or with WEB-INF/lib/production.jar each of which containing META-INF/resources/config.properties file with different content. The application code reading the configuration would always access it using ./config.properties (or http://host:port/webcontext/config.properties).

Note this mechanism also applies to JSPs and that resource files placed in the document root take precedence. Get all the details from paragraph 10.5 of the Servlet 3.0 specification.

Try this out today in GlassFish 3 and above.

mercredi août 13, 2008

NetBeans 6.5 beta est disponible


On ne chôme pas au coeur de l'été chez NetBeans. Je suis sur un build intermédiaire de NetBeans 6.5 depuis fin juillet (après M1) et je compte passer à la 6.5 beta qui est maintenant disponible avec une collection de nouvelles fonctionnalités :
• Ouverture confirmée aux langages autres que Java (au delà de C/C++ et jRuby): Groovy et Grails (clin d'oeil à Guillaume ;), JavaScript (éditeur et débugger pour Firefox et IE), et PHP. C'est vrai dans l'IDE et son éditeur, mais aussi dans ses runtimes (GlassFish v3 par exemple)
• "Compile on Save" et "Deploy on change" (mais que reste-il à Eclipse ;-)
• intégration de GlassFish v3 "Prélude" prévu pour l'automne (kernel OSGi, démarrage ultra-rapide, support Web Conteneur Java, jRuby/Rails, Groovy/Grails, etc...)
• Complétion de code dans l'éditeur SQL et autres améliorations
• Complétion de code CSS/HTML
• Intégration native du support Hibernate (clin d'oeil à Emmanuel ;)
• Amélioration du JSF CRUD Generator (Ajax et plus flexible)
• Plus besoin de rajouter la bibliothèque Subversion (historiquement nécessaire pour des raisons de licence)
• autres fonctionnalités décrites sur le wiki...

Comme toujours les téléchargements sont proposés entre 18Mb tout mouillé pour C/C++ (Java SE est à 28Mb et PHP à 20Mb) au tout-en-un qui fait 203 Mb (3 runtimes Java EE, JavaME et tous les outils SOA inclus) et la possibilité d'installer petit et de rajouter tout le reste avec le centre de mise à jour.

jeudi nov. 16, 2006

F3, Phobos and Shoal


Of course the "Java Libre" news from Sun is this week's big news..
I would also like to point to three new code drops:
- Shoal : JXTA for GlassFish Clustering. Overview here.
- F3 : quite elegant Swing scripting (call it a DSL if you want), an animation library and much more all about to be open sourced.
- Phobos : server-side scripting with development and debug tools and REST & Atom support.

Phobos is being noticed in several places. I'm very curious to see how it plays out.
Actually, all of the abovecould be combined. Kinda fun having Swing on the client and JavaScript on the server....

About

This blog has moved

Alexis Moussine-Pouchkine's Weblog

GlassFish - Stay Connected

Search

Archives
« avril 2014
lun.mar.mer.jeu.ven.sam.dim.
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today
Blogroll

No bookmarks in folder

News

No bookmarks in folder