J2EE Web projects and applications
In the WebSphere Studio workbench, you create and maintain resources for Web applications in Web projects. There are two types of Web projects, J2EE and static. J2EE web projects contain dynamic J2EE resources such as servlets, JSPs, filters, and associated metadata, in addition to static resources such as images and HTML files. Static web projects only contains static resources. When you create Web projects, you can include cascading style sheets and JSP tag libraries (for J2EE projects), using the Create a Web Project wizard, so that you can begin development with a richer set of project resources.
J2EE Web projects are always imbedded in Enterprise Application projects. The wizards that enable you to create a Web project or to import a WAR file require that an Enterprise Application project be specified. When you complete these wizards, they will update the application.xml deployment descriptor of the specified Enterprise Application project to define the Web project as a module element.
J2EE conventions may represent extra overhead if you only want to create a static, content-based Web application, which contains no dynamic files, such as JSPs or servlets. In this case, when you only need the most basic functions of a WebSphere Studio Web project, you may prefer to use the static Web project type. Static Web projects can later be converted to J2EE Web projects.
The J2EE model, and more specifically, the Sun Microsystems Java Servlet 2.3 Specification, defines a Web application directory structure that specifies the location of web content files, class files, classpaths, deployment descriptors, and supporting metadata. The Web project hierarchy mirrors that of the Web application created from a project. In the workbench, you can use the Create a Web Project wizard to create a new Web project.
The main project folder contains all development objects related to a Web application. The Web Content folder contains the elements of the project necessary to create a Web application. This folder structure maps to the Web application archive (WAR) structure defined by Sun. The following default elements are located in the Web project folder hierarchy:
Web Deployment Descriptor - The standard Web application deployment descriptor.
Java Source - Contains the project's Java source code for classes, beans, and servlets. When these resources are added to a Web project, they are automatically compiled and the generated files are added to the WEB-INF/classes directory. The contents of the source directory are not packaged in WAR files unless an option is specified when a WAR file is created.
Web Content - The mandatory location of all Web resources, including HTML, JSP, graphic files, and so on. If the files are not placed in this directory (or in a subdirectory structure under this directory), the files will not be run on the server. The Web Content folder represents the contents of the WAR file that will be deployed to the server. Any files not under the Web Content folder are considered development-time resources (for example, .java files, .sql files, and .mif files), and are not deployed when the project is unit tested or published.
META-INF - This directory contains the MANIFEST.MF file, which is used to map classpaths for dependent JAR files that exist in other projects in the same Enterprise Application project. An entry in this file will update the run-time project classpath and Java build settings to include the referenced JAR files.
theme - The suggested directory for cascading style sheets and other style-related objects.
WEB-INF - Based on the Sun Microsystems Java Servlet 2.3 Specification, this directory contains the supporting Web resources for a Web application, including the web.xml file and the classes and lib directories.
/classes - This directory is for servlets, utility classes, and the Java compiler output directory. The classes in this directory are used by the application class loader to load the classes. Folders in this directory will map package and class names, as in: /WEB-INF/classes/com/mycorp/servlets/MyServlet.class. Do not place any .class files directly into this directory. The .class files are placed in this directory automatically when the java compiler compiles java source files that are in the Java Source directory. Any files placed directly in this directory will be deleted by the java compiler when it runs.
/lib - The supporting JAR files that your Web application references. Any classes in .jar files placed in this directory will be available for your Web application
Libraries - The supporting JAR files that your Web application references. This folder mirrors the content of the lib folder. In addition, Web Library Projects, which are "virtual" JAR files that do not physically reside in the Web project, but are associated with Java projects elsewhere in your workspace, are included in this folder. They are packaged with your project when you export the application's WAR file.
Note: A library entry on the Java build path will remain there unless the actual JAR file is deleted from the WEB-INF/lib folder. If you remove a library path entry but not the JAR file, the library entry will be re-added to the path automatically.
Creating an enterprise application project
Enterprise application projects contain references to the resources needed for enterprise applications and can contain a combination of Web modules, JAR files, connector modules, EJB modules, and application client modules. An enterprise application project is deployed in the form of an EAR file. In WebSphere Studio, the modules in an enterprise application project are mapped to other J2EE projects. The mapping information is stored in metadata files within the enterprise application project. The metadata files are used for exporting the project to an EAR file, and for running the project on the server.
Complete the following steps to easily create an enterprise application project:
Switch to the J2EE perspective.
Select File > New > Enterprise Application Project.
Select the J2EE specification level to which you want your project to adhere.
Type an enterprise application project name.
Note: To change the default file system location where resources you create are stored or to include files in your new project that already exist in an accessible directory, uncheck the Use default location checkbox and type a new fully qualified path.
Two [three] check boxes are provided for the application client project, [EJB project], and Web project that can be optionally created. When you type in the enterprise application project name, the default names for the three additional modules projects are automatically updated. You can uncheck any of them.
New Enterprise Application project (EAR project, Application Client project, WAR project):
Creating new J2EE Web projects
In the workbench, you create and maintain resources for Web applications in Web projects. Use the Create a Web Project wizard to create a new J2EE Web project, as follows:
To launch the Web Project wizard in the Web perspective, select File -> New -> Web Project:
Note: From other perspectives, launch the Web Project wizard by selecting File -> New -> Project. Then select the Web option, Web Project, and then the Next button.
Provide a name and storage location for the Web project:
Click the J2EE Web Project radio button.
Optionally, select one or more of the Web Project features, such as the Create a default CSS file checkbox, which creates a default CSS file (called Master.css) for any HTML and JSP files included in the project.
You can also add custom tag libraries for various purposes. When you select a feature, a description is provided.
Specify the name of a new or existing Enterprise Application project that the new Web project should be associated with for purposes of deployment.
Note: If you want to add a Web project as a module to another Enterprise Application project in the future, you can open the application.xml editor for the Enterprise Application project and select the Add option in the General page.
Specify a context root for the Web project. The context root is the Web application root, the top-level directory of your application when it is deployed to a Web server. You can change the context root after you create a project using the project Properties dialog, which you access from the project's context menu. The context root can also be used by the links builder to ensure that your links remain ready to publish as you move and rename files inside your project.
From the J2EE Level drop-down list, select the appropriate Sun Microsystems Servlet and JSP specification level for the dynamic elements to be included in your Web project. It is recommended that any new servlets and JSP files that you expect to create should adhere to the latest specification level available; previous specification levels are offered to accomodate any legacy dynamic elements that you expect to import into the project. By default, the Web project's J2EE level is set to the Workbench's J2EE level. Project preferences are initialized when the project is created. If you want to update these preferences, select Window > Preferences > J2EE, and then choose the appropriate J2EE level from the J2EE property settings. If you choose to create a new Enterprise Application project for this Web project, the J2EE level setting controls the level of the resulting EAR file as well.
Click Next if you wish to configure module dependency information, or if you need to supply additional information for any of the Web project features that you selected in the first page of the wizard. Otherwise, click Finish, the wizard will create an empty project container primed with the appropriate folder structure, along with a deployment descriptor file that describes the current project.
In the Module Dependencies page, select and set dependent JAR files for modules within the associated Enterprise Application project. Specifying dependencies on this page updates the runtime classpath and Java project build path with the appropriate JAR files. Supply values for the following fields:
The Project name field displays the Web project name entered on the previous page of the wizard.
The Enterprise Application project name field displays the Enterprise Application project name entered on the previous page of the wizard.
Use the Available dependent JARs field to select JAR files that are required at runtime.
The Manifest Class-Path displays the classpath for the selected JAR file(s).
Click the Next button if you need to supply additional information for any of the Web project features that you selected in the first page of the wizard. If you click Finish, the wizard will create an empty project container primed with the appropriate folder structure, along with a web.xml file that describes the current project.
The new project will reflect the J2EE folder structure that specifies the location of web content files, class files, classpaths, the deployment descriptor, and supporting metadata. You can begin creating or importing content, using Web resource editors or the Import wizards.