Preparing to Use Struts 2
On this page:
- Before you start
- Creating a Module with a Struts 2 Facet
- Adding a Struts 2 Facet to a Module
- Defining the Validation File Set
Before you start
Make sure the Web and Struts2 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 2 is enabled through the Web and Struts 2 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 Struts 2 facet can be only added as a child of a Web facet. Note that only one Struts 2 facet is allowed in a module.
Creating a Module with a Struts 2 Facet
When you create a Struts 2 module with the dedicated Web and Struts 2 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 Struts 2 check box.
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.)
Select this option to download
the library files that implement Struts 2.
(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.
- 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 a web node with a web application descriptor
- Creates a Struts 2 configuration file
struts.xmland adds it to the src node.
- Adds the required Struts 2 libraries.
Adding a Struts 2 Facet to a Module
When you add a Struts 2 facet to an existing module, IntelliJ IDEA downloads and adds the necessary libraries automatically.
A Struts 2 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 2 facet in a module is allowed.
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 Facet node and select on its context menu.
- Select on the context menu of available facets. The right-hand pane displays the Facet Struts 2 dialog.
- In the File Sets tab, specify the configuration files to validate.
- If some additional libraries are required, the corresponding warning message displays. Click Fix. The necessary libraries will be downloaded and added automatically.
Defining the Validation File Set
Adding a Validation File Set
- Open the Struts 2 Facet page.
- Switch to the File Sets tab.
- Click (Alt+Insert). The Edit File Set dialog opens showing the module tree.
- In the File Set Name field, specify the name of the new file set.
- To add a file to the set, select the check box next to its name.
- To add a file that is not displayed in the tree, click Locate and select the the required files in the Select Path dialog.
Editing a Validation File Set
- Select the file set on the File Sets tab and click (Enter). The Edit File Set dialog opens.
- To add files to the file set, select the check boxes next the required files and click OK.
- To remove a file, select the file and click (Alt+Delete).