Preparing to Use Struts
On this page:
- Before you start
- Creating a Module with a Struts Facet
- Adding a Struts Facet to a Module
- Customizing the Struts Facet
Before you start
Make sure the Web and Struts1.x bundled plugins are enabled. The plugins are bundled with IntelliJ IDEA and activated by default. If the plugins are not activated, enable them on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.
Integration with Struts is enabled through the Web and Struts1.x facets. These dedicated facets contain settings, configuration file paths, and validation rules. This information determines the structure of a module so IntelliJ IDEA detects how to treat the module contents.
A Struts1.x facet can be only added as a child of a Web facet. Note that only one Struts1.x facet is allowed in a module.
Creating a Module with a Struts Facet
When you create a Struts module with the dedicated Web and Struts facets, IntelliJ IDEA configures the module, downloads and adds all the necessary libraries automatically.
Do one of the following:
If you are going to create a new project:
click Create New Project on the Welcome screen or
select File | New | Project.
As a result, the New Project wizard opens.
If you are going to add a module to an existing project:
open the project you want to add a module to, and
select File | New | Module.
As a result, the New Module wizard opens.
- If you are going to create a new project: click Create New Project on the Welcome screen or select File | New | Project.
- On the first page of the wizard, in the left-hand pane, select Java. In the right-hand part of the page, specify the JDK that you are going to use.
Under Additional Libraries and Frameworks, select the Web Application check box.
Select the version of the Servlet specification to be supported from the Versions list.
If you want the deployment descriptor
web.xmlfile to be created, select the Create web.xml check box.
- Select the Struts check box.
- Select the Struts version from the Version list.
a library that implements
You can choose to use an existing library, create and use a new one,
download the library files if they are not yet available on your computer,
or postpone setting up the library until a later time.
Select the library to be used from the list
(if the corresponding library is already defined in IntelliJ IDEA).
Create. If the corresponding library files (
.jar) are already available on your computer, you can arrange those files in a library and use that new library. To do that, click Create and select the necessary files in the dialog that opens. (Use the Ctrl key for multiple selections.)
Optionally, click Configure to edit the selected library. (For an existing library the Edit Library Dialog will open, for the library that you have just created - the Create Library Dialog.)
Select this option to download
the library files that implement the selected Struts version.
(The downloaded files will be arranged in a library.)
Optionally, click Configure to edit the library settings and contents. (The Downloading Options Dialog will open.)
- Set up library later. Select this option to postpone setting up the library until a later time.
Configure. Click this button to edit the settings for the library selected next to Use library or the one that is about to be downloaded.
- Use library. Select the library to be used from the list (if the corresponding library is already defined in IntelliJ IDEA).
- Specify the name and location settings. For more information, see Project Name and Location or Module Name and Location.
IntelliJ IDEA configures the new module as follows
- Creates the structure of the module with the Web and WEB-INF nodes.
Creates a Web application deployment descriptor
Web.xmlunder the WEB-INF node for versions 2.2 - 2.5.
- Creates a Struts configuration file
struts-config.xmlunder in the WEB-INF node.
- Configures an Action servlet in
- Downloads and installs the libraries that implement Struts.
Adding a Struts Facet to a Module
When you add a Struts facet to an existing module, IntelliJ IDEA downloads and adds the necessary libraries automatically.
A Struts facet can be added only as a child of a Web facet. If the module has no Web facet, add it first. Also note that only one Struts facet is allowed in a module.
This will change the configuration of the module.
- Open the Module Settings dialog box.
- In the Modules node, right-click the relevant module.
- To add a Web facet, choose from the context menu. In the drop-down list of available facets, select .
- Right-click the Web node and select on its context menu.
- Select on the context menu of available facets. The right-hand pane displays the Facet 'Struts' dialog.
- Customize the Struts facet settings in the Struts Features and Validation tabs.
- If some additional libraries are required, the corresponding warning message displays. Click Fix. The necessary libraries will be downloaded and added automatically.
Customizing the Struts Facet
After you have enabled the basic Struts support, IntelliJ IDEA provides the ability to add more Struts features by customizing the Struts dedicated facet.
- Open the settings of the Struts facet from the module in question.
- The Struts Features tab shows
a list of additional Struts components:
To enable support of a component from the list, select the check box next to it.
- In the Validation tab, specify the files to validate
and the validation settings:
To enable validating the configuration file of a particular component, select the relevant check box. IntelliJ IDEA will check
whether the selected component can be supported correctly using the available resources and suggest to download the missing libraries,
Validation can be enabled for the configuration files of the following components:
Specify the validation settings:
- To get informed on errors detected during validation, select the Report errors as warnings check box.
- To exclude Struts property keys from validation, select the Disable property keys validation check box.
- To enable validating the configuration file of a particular component, select the relevant check box. IntelliJ IDEA will check whether the selected component can be supported correctly using the available resources and suggest to download the missing libraries, if necessary.