> Overview (Steps)

Struts lesson 2: JSP-files packed into an EAR (Enterprise-ARchive)

For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

Last revision of this document:
2005-07-01

This document describes the creation of a JSP-file (JSP – Java Server Page) with integrated functionality to display time and TCP/IP_address of the caller.
This lesson is using the Struts-framework (see JS_Struts00) under
Eclipse, packing the JSP-files into a WAR, defining parameters in the 'application.xml'-file, packing the files into one EAR (Enterprise Archive) file and deploying the EAR-file to JBoss-Java-Application-Server.

In the 'application.xml'-file is another 'context-root' defined. This allows to call the site under another name than the name of the WAR- or EAR-file.

Credits:

I derived that lesson from a lot of sources found in the internet. I thank the numerous authors for their contribution.

Prerequisites:


Preparation:

Create a new project (named JS_Struts02) by copying the Struts-framework (JS_Struts00):

In the 'Package Explorer' window you should see a new project with the name 'JS_Struts02' with the following structure.
(You can expand/collapse the structure by clicking onto the triangles left of the folders.)

top.

Writing the JSP-code:

Write the start-page (index.jsp) – which will be the only page in this lesson.

Aim of this lesson is mainly to write a JSP-file an create an EAR; so the JSP- and HTML-code is kept pretty simple.
There is one 'index.jsp' file which displays the current date/time and the TCP/IP-address of the caller.

A short explanation of the newly introduced elements in the code.
These elements are interpreted by the Java-Application-Server as soon as the web-page is called.

top.

Making the packaging configuration and pack the HTML-files into a WAR (Web-ARchive):

This is an intermediate step in this lesson as the final aim is an EAR (Enterprise Archive) file.
The WAR-file can be deployed to the Java-Application-Server for an intermediate test.

Define, which files are packed into the WAR – in this lesson it is only one.

top.

Intermediate Run / Test:

Before the lesson continues with packaging into an EAR-file, it is advisible to verify, if the WAR-file with the 'index.jsp'-file is error free.
The simpliest check is, to deploy the WAR-file to the Java-Application-Server.

For the conceptional background of deployment to a Java-Application-Server and the assumptions of the directories with the Eclipse-workspace and and the Java-Application-Server-deployment, please see Run / Test in JS_Struts01 – HTML in a WAR .

Note: There is also a functionality in Eclipse to define the Java-Application-Server and deploy and undeploy with an Eclipse-function.
I was not pretty happy with that feature. My
JBoss-Application-Server is running on another machine. When this machine is not running during the start of Eclipse, the Eclipse-function gets confused, reports that a changed WAR-file is deployed - but the old file is not overwritten.
So I prefer to stay on the more secure side and copy the files using the 'Terminal'-window.

top.

Defining of the 'application.xml'-file as a prerequisite for an EAR (Enterprise-ARchive):

As the project should be registered under another name (strutslesson02) than the name of the WAR-file (JS_Struts02.war), it is necessary to find out which parameter-file is responsible for that.
As the concept of the WAR does not know a different registration-name, the WAR-file (and the parameter-file(s)) is packed into an EAR (Enterprise-ARchive) file.
In one of the following lessons is also shown, that the EAR can contain other parameter-files, e.g. references to a database.



Define the (different) registration name (strutslesson02) under which the web-site will be registered in the Java-Application-Server.
This parameter is set.

A short explanation of the elements in the parameters.
These elements are interpreted by the Java-Application-Server as soon as the web-page is called.

top.

Making the packaging configuration and pack the files into an EAR (Enterprise-ARchive):

This is the final packaging-configuration.

Pack the WAR-file and the 'application.xml' parameter-file into the EAR-file..

top.

Run / Test:

This is the final verification if the generated 'JS_Struts02.ear' file (with an Enterprise ARchive structure) is running error-free within a Java-Application-Server.

For the conceptional background of deployment to a Java-Application-Server and the assumptions of the directories with the Eclipse-workspace and and the Java-Application-Server-deployment, please see Run / Test in JS_Struts01 – HTML in a WAR .

Note: There is also a functionality in Eclipse to define the Java-Application-Server and deploy and undeploy with an Eclipse-function.
I was not pretty happy with that feature. My
JBoss-Application-Server is running on another machine. When this machine is not running during the start of Eclipse, the Eclipse-function gets confused, reports that a changed WAR-file is deployed - but the old file is not overwritten.
So I prefer to stay on the more secure side and copy the files using the 'Terminal'-window.


top.

Related Documents: