Now that you're convienced that creating a web-application module is a good idea, let's see how you can do so. I've added a complete web-application module to our source code examples. The module contains a simple servlet and and even simpler taglibrary to showcase the FirstSpirit specific parts.
Grab the fs-access.jar (located at /data/fslib) and the fs-client.jar (/web/fs4root/clientjar) from your FirstSpirit server. Copy them to /examples/FS_V4_mod/lib. These two libraries are needed to compile the examples. You'll also need a servlet-api.jar and a jsp-api.jar. They're are shipped with every Tomcat/Glassfish/Jetty installation. Your IDE may ship them as well.
Edit the setenv.sh (setenv.bat if you're on windows) and adjust the path to your JDK.
Execute setenv.sh or setenv.bat to configure the build environment.
Perform a "ant assemble-all" to build all modules, including the web-application example. If you just want to build the web-application example, run "ant assemble-fsm" within the examples/FS_V4_mod/webapp/ directory.
Install the module on a FirstSpirit server
Locate the fsm file under examples/FS_V4_mod/webapp/target/fsm
Install the newly created fsm archive in the 'Server and Project Configuration', Server -> Server properties -> Modules -> Install
Edit your project, go to the "web components" section and add the module to an environment. Refer to the admin documentation (section 7.3.16 Web applications) for details. Add it at least to the Preview and Production environment.
Please note that you're able to edit the web.xml, which shipped with the module, by clicking the "web.xml" button. That feature is provided out of the box. Clicking on the "Confgure" button will show you a simple, Swing based, configuration screen.
Verify it's working
Switch to the "Preview" environment tab and click on the "Update" button at the top. This will deploy the web-application to your internal Jetty.
Create a new page template (or modify an existing one) to include the new JSP-Tag.
Every working? Great, so let's have a closer look at our webapplication:
The taglib implements one simple "hello world" tag. Nothing fancy here.
The servlet is nearly as simple as the taglib. It implements a very simple hit counter ("This servlet has been called x times."). The two configuration options are controlled via a java properties file named "configuration.properties".
You already know, we're using Ant as a build tool. The build.xml contains all normal ant tasks, necessary to build a Java based project (compile, create jars). The task to create our module (.fsm file) is called "assemble-fsm". As I mentioned in my previous blog post, a fsm file isn't much more than a renamed jar file, containing a module.xml.
Here's the file structure of the generated fsm file:
This file contains the configuration options for our servlet.