The Struts binary distribution needs three other software packages installed to operate. You may already have these installed on your system. To build Struts from source you may need to acquire and install several others. The complete list is as follows:
- Java Development Kit - You must download and install a Java2 (version 1.2 or later) Java Development Kit implementation for your operating system platform. A good starting point for locating Java Development Kit distributions is http://java.sun.com/j2se. To build Struts, Java 1.4.2 (the latest production JDK) is suggested.
- Servlet Container - You must download and install a servlet container that is compatible with the Servlet API Specification, version 2.2 or later, and the JavaServer Pages (JSP) Specification, version 1.1 or later. One popular choice is to download Apache's Tomcat, but any compliant container should work well with Struts.
- XML Parser - Struts requires the presence of an XML parser that is compatible with the Java API for XML Parsing (JAXP) specification, 1.1 or later. This is bundled with J2SE 1.4 and later. For earlier versions of Java, the easiest way to obtain JAXP is probably by downloading the Web Services Developers Kit (1.1 or later!). See the Sun JAXP FAQ for more information.) In Struts-based web applications, you may replace the reference implementation classes with any other JAXP compliant parser, such as Xerces. See detailed instructions related to the parser in the instructions for building and installing Struts, below.
Ant Build System - If you are building Struts from the
source distribution, you must download and install version 1.5.4 (or later)
of the Ant build system.
- Make sure that the "ant" and "ant.bat" scripts are executable, by adding the $ANT_HOME/bin directory to your PATH environment variable.
- Copy and review either the "build.properties.sample" or "build.properties.sample.lib" file as "build.properties". The latter is recommended if you are not active in Jakarta Commons development.
- Maven property files are also provided, but the Maven build is still experimental. New developers may find Maven easier to use, since it acquires the appropriate JARs automatically.
Servlet API Classes - In order to compile Struts itself,
or applications that use Struts, you will need a
servlet.jarfile containing the Servlet and JSP API classes. Most servlet containers include this JAR file. Otherwise, you can get the Servlet API classes distribution from here.
JDBC 2.0 Optional Package Classes - Struts supports
an optional implementation of
javax.sql.DataSource, so it requires the API classes to be compiled. They can be downloaded from http://java.sun.com/products/jdbc/download.html.
Other Packages - Struts utilizes several
packages from other open source projects, especially the Jakarta
These are the packages which must be available if you wish to
build Struts from source:
- ANTLR (Version 2.7.2)
- Jakarta Commons Beanutils (Version 1.6.1)
- Jakarta Commons Collections (Version 2.1)
- Jakarta Commons Digester (Version 1.5)
- Jakarta Commons FileUpload (Version 1.0)
- Jakarta Commons Logging (Version 2.0)
- Jakarta Commons Logging (Version 1.0.4)
- Jakarta Commons Validator (Version 1.1.3)
- Jakarta ORO (Version 2.0.7)
libsub-directory with each release distribution. Please note that the minimum requirements may change between releases, and some JARs may need to be updated to use the latest Nightly Build.
Xalan XSLT Processor - If you are building Struts from
the source distribution, you will need a version of Xalan to perform
XSLT transformations. If you are using the JAXP/1.1 XML parser, you
should use the version of
xalan.jarshipped with it. Otherwise, download and install version 1.2 of Xalan from here.
- Unit tests - To verify your build against the JUnit and Cactus unit tests, three other packages must be available:
Install A Struts Binary Distribution
Unpack the Struts binary distribution into a convenient directory. (If you build Struts from the source distribution, the result of the build will already be an unpacked binary distribution for you). The distribution consists of the following contents:
lib/*.jar - The struts.jar contains the Java classes
distributed by the Struts project. The other JAR files contain packages
from other projects that are imported by Struts. When you launch
a Struts-based application, these JARs need to be available to your
application, usually by copying them to the application's
WARNING - If you are going to be hosting multiple Struts based applications on the same servlet container, you will be tempted to place the
struts.jarfile into the shared repository supported by your container. Be advised that this may cause ClassNotFoundException problems unless all of your application classes are stored in the shared repository.
lib/*.tld - These are the "tag library
descriptor" files that describe the custom tags in the various Struts
tag libraries. The tld file for any Struts taglibs that you use should
be copied into the
WEB-INFdirectory of your web application. (Applications under Servlet 2.3 containers can omit this step if the standard uri is referenced.)
- webapps/struts-blank.war - This is a simple "web application archive" file containing a basic starting point for building your own Struts-based applications.
- webapps/struts-documentation.war - This is a "web application archive" file containing all of the Struts documentation found on the Struts web site (including these pages). You can install this web application on any servlet container compatible with Servlet API 2.2 or later.
webapps/struts-examples.war - This "modular"
applications combines several usefule demonstrations:
- Exercise-Taglib - This application module contains test pages for the various custom tags distributed with Struts. It is primarily of use to developers who are enhancing the Struts custom tag libraries, but may also be useful as simple examples of the usage of various Struts tags.
- Upload - This application module is a quick example of uploading files using the Struts framework.
- Validator - This application module is an example of using the validator framework, using both the server-side and optional client-side validation.
- webapps/struts-mailreader.war - This is an example web application that uses a large percentage of Struts features. You can install this web application on any servlet container compatible with the Servlet 2.2 (or later) and JSP 1.1 (or later) specifications. If an XML parser is not made available to web applications by your container, you will need to add one to the WEB-INF/lib directory of this web application.
- webapps/tiles-documentation.war - This web application documents how to use tiles, and was developed using tiles.
To use Struts in your own application, you will need to follow these steps:
- Copy the
lib/*.jarfiles from the Struts distribution into the
WEB-INF/libdirectory of your web application.
- Copy the
lib/*.tldfiles for any Struts taglibs you use from the Struts distribution into the
WEB-INFdirectory of your web application.
- Modify the
WEB-INF/web.xmlfile for your web application to include a
<servlet>element to define the controller servlet, and a
<servlet-mapping>element to establish which request URIs are mapped to this servlet. Use the
WEB-INF/web.xmlfile from the Struts example application for a detailed example of the required syntax.
- Modify the
WEB-INF/web.xmlfile of your web application to include the following tag library declarations (Servlet 2.3 can omit this step if the standard uri is referenced):
<taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib>
- Create a file
WEB-INF/struts-config.xmlthat defines the action mappings and other characteristics of your specific application. You can use the
struts-config.xmlfile from the Struts example application for a detailed example of the required syntax.
- At the top of each JSP page that will use the Struts custom tags, add line(s) declaring the Struts custom tag libraries used on this particular page, like this:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-html" prefix="html" %> <%@ taglib uri="/tags/struts-logic" prefix="logic" %>
- When compiling the Java classes that comprise your application, be sure to include the JAR files (copied earlier) on the CLASSPATH that is submitted to the compiler.
Installing Struts With Your Servlet Container
For most containers, you need only to:
- Copy the WAR files in your Struts
/webappdirectory to your containers
- In some cases, you may need to restart your container if it is running.
Running Struts Applications Under A Security Manager
Many application servers execute web applications under the control of a Java security manager, with restricted permissions on what classes in the web application can do. If you utilize form beans with mapped properties, you may encounter security exceptions unless you add the following permission to the set of permissions granted to your Struts application's codebase:
permission java.lang.RuntimePermission "accessDeclaredMembers";
Consult the documentation on your application server for more information about how to configure additional security manager permissions.
Installing Struts on Various Containers
- Bluestone Universal Business Server 7.2 - Additional steps required.
- Borland Application Server 4.5 -No additional steps required.
- iPlanet Application Server - Service Pack 2 is recommended. Note that the database object in the Struts-Example application is not compatible with this container.
- iPlanet Web Server - Additional steps required.
- iPortal Application Server - Additional steps required.
- Jetty - Additional steps required.
- JRun - Additional steps required.
- Novell ExteNd Application Server 4.0+ - Additional steps required.
- Orion Application Server - Additional steps required.
- Resin 1.2+ "standalone" - No additional steps required.
- RexIP - No additional steps required.
- SilverStream 3.7.1 and later - Additional steps required.
- Tomcat 3.1 and prior - Not recommended. Use Tomcat 3.2.1 or later.
- Tomcat 3.2.1 with Apache - Additional steps required.
- Tomcat 3.2.1+ "standalone" - No additional steps required.
- Tomcat 4.0 - No additional steps required.
- Trifork Enterprise Application Server 3.3.x - No additional steps required.
- Weblogic 5.1 sp8 - Additional steps required.
- WebLogic 6.0+ - No additional steps required.
- WebSphere - Additional steps required.
- WebSphere - Steps for the Example Application.
Building Struts From Source
To build Struts, you will need to customize the build process to the details of your development environment as follows:
- The Struts source distribution uses a file named
build.properties(in the top-level directory of the distribution) to identify the location of external components that Struts depends on.
- There is no
build.propertiesfile included with the source distribution. However, there is an example file named
build.properties.examplethat you can copy to
build.propertiesand then customize.
- The properties you must configure in
catalina.home - Pathname to the directory of your
binary distribution of Tomcat 4.0 (required only if you wish to
- commons-beanutils.jar - Pathname of the BeanUtils package JAR file from the Jakarta Commons project.
- commons-collections.jar - Pathname of the Collections package JAR file from the Jakarta Commons project.
- commons-digester.jar - Pathname of the Digester package JAR file from the Jakarta Commons project.
- commons-fileupload.jar - Pathname of the Fileupload package JAR file from the Jakarta Commons project.
- commons-lang.jar - Pathname of the Lang package JAR file from the Jakarta Commons project.
- commons-logging.jar - Pathname of the Logging package JAR file from the Jakarta Commons project.
- commons-validator.jar - Pathname of the Validator package JAR file from the Jakarta Commons project.
- servletapi.home - Pathname to the directory of your binary distribution of the Servlet API classes.
tomcat.home - Pathname to the directory of your
binary distribution of Tomcat 3.2 (required only if you wish to
xerces.home - Pathname to the directory of your
binary distribution of the Xerces parser, version 1.2 or 1.3
(required only if you wish to use the
- catalina.home - Pathname to the directory of your binary distribution of Tomcat 4.0 (required only if you wish to use the
- If you are a Struts developer with write access to the CVS repository,
be sure that you do NOT check in a copy of the
build.propertiesfile, since it will be different for each individual developer.
To build a "distribution" version of Struts, first change your current
directory to the directory in which you have unpacked the Struts
source distribution, and (if necessary) create or customize the
build.properties file as described above. Then, type:
This command will create a binary distribution of Struts, in a
dist (relative to where you
are compiling from). This directory contains an exact replica of the
files included in a binary distribution of Struts, as described
in the preceding section.
IMPORTANT NOTE: The
struts.jar, as well as the JAR files
from the Jakarta Commons project, must be in your classpath when
compiling Struts. The
build.xml provided does this
automatically. If you use your development machine to test Struts
application locally, be sure that the
NOT on your classpath when your container is running.
Next: FAQs and HowTos