HomeDocumentation > Reference > Samples > Java EE sample applications > jarresource-javaee6 - A simple bundled resources example
{scrollbar}

Application Overview

This sample application bundles a JAR file, namely jarresource-javaee6-jar-3.0-M1.jar in its WEB-INF/lib directory and the sample application contains both dynamic and static resources(index.html, head.html, jarresource.jsp) in its META-INF/resources directory. All these resources can be accessed as if they are in the application's root directory. Prior to Servlet 3.0, this may result in a 404 response.

Once the resources are requested, it will first search the root of the web application context for the requested resource before looking at any of the JAR files in the WEB-INF/lib directory. The order in which the JAR files in the WEB-INF/lib directory are scanned is undefined.

Application structure

The full-blown of the application structure is depicted as the following:

+- WEB_INF

|_ web.xml

|_ geronimo-web.xml

+- lib

+- jarresource-javaee6-jar-3.0-M1.jar

+- META-INF

+- resources

|_ index.html

|_ header.html

|_ jarresource.jsp

Application Implementation

web.xml specifies the welcome file list, we use index.html as enclosed by <welcome-files/> tags in the sample.

xmlweb.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="jarresource-javaee6"> <description>jarresource-javaee6 Servlet Sample</description> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>

geronimo-web.xml specifies the module's dependency information and entry point of the application.

Information about the project such as module's unique name, dependencies is described inside the <sys:environment/> tags. It is one of the best practices to give your module an unique identification, so that it can later be referenced by some other deployable applications. In our sample application, the module is grouped as org.apache.geronimo.samples. The path specified in the <context-root/> tags is the entry point of the URL used to access this web application. Therefore the sample application can be accessed at http://<hostname>:<port>/jarresource-javaee6.

xmlgeronimo-web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"> <sys:environment> <sys:moduleId> <sys:groupId>org.apache.geronimo.samples</sys:groupId> <sys:artifactId>jarresource-javaee6</sys:artifactId> <sys:version>3.0-M1</sys:version> <sys:type>car</sys:type> </sys:moduleId> <sys:dependencies/> <sys:hidden-classes/> <sys:non-overridable-classes/> </sys:environment> <context-root>/jarresource-javaee6</context-root> </web-app>

index.html is placed in the META-INF/resources directory of the JAR file which is then bundled in the WEB-INF/lib directory of this jarresource-javaee6 application.

The <frameset> tag in index.html defines a frameset.The frameset element holds two frame elements which indicate two separate documents header.html and jarresource.jsp.

htmlindex.html ... <FRAMESET rows="86px,*" frameborder="0"> <FRAME src="./header.html" name="headerFrame" title="Header" frameborder="0" marginheight="0" marginwidth="0" noresize scrolling="no"> <FRAME src="./jarresource.jsp" name="sampleDocumentFrame" title="Sample Document Description" frameborder="0" marginheight="0" marginwidth="0" noresize scrolling="yes"> </FRAMESET> ...

jarresource.jsp is used to render output on the screen.

htmljarresource.jsp ... <body> <font face="Verdana, Helvetica, Arial"> This is a JSP executed inside a jar file of the web module. </FONT> <br/> The remote host is <%=request.getRemoteHost()%>. <br/> </body> ...

Get Source Code

Please reference Samples General Information for information on obtaining and building the source for this and other samples.

Build the web application

Once all the sources get checked out the next step is to build jarresource-javaee6 sample. It requires Maven 2 for building the binaries.

From the < jarresource-javaee6_home> directory run the following command:

solid

mvn clean install

This process will take a couple of minutes according to the availability of jar files in your local maven repository. The binaries will be generated in the corresponding target directory .

Deploy the web application

Deploying sample application is pretty straight forward as we are going to use the Geronimo Console.

  1. Click Deploy New form the left navigation panel on the console
  2. Load jarresource-javaee6-war-3.0-M1.war from jarresource-javaee6-war\target folder in to the Archive input box.
  3. Press Install button to deploy application in the server.

Test the web application

The app is accessible at http://localhost:8080/jarresource-javaee6.