IntelliJ IDEA 2019.2 Help

Prepare to use Struts 2

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.

Before you begin, make sure the Web and Struts2 bundled plugins are enabled. The plugins are activated by default. If the plugins are disabled, enable them on the Plugins page as described in Managing plugins.

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.

Create 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.

  1. Open the project to which you want to add a module and select File | New | Module.

    As a result, the New Module wizard opens.

  2. In the left-hand section, select Java.

  3. In the right-hand section, specify the JDK that you want to use.

  4. Under Additional Libraries and Frameworks, select the Web Application checkbox, and select the version of the Servlet specification from the Versions list.

  5. If you want the deployment descriptor web.xml file to be created, select the Create web.xml checkbox.

  6. From the Additional Libraries and Frameworks list, select Struts 2.

  7. You'll need a library that implements Struts 2. 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.

    Adding a new Struts 2 module

  8. On the next step of the wizard, specify the module name and location and click Finish.

IntelliJ IDEA configures the new module as follows:

  • Creates a web node with a web application descriptor web.xml.

  • Creates the Struts 2 configuration file struts.xml and adds it to the src node.

  • Adds the required Struts 2 libraries.

Add the Struts 2 facet to a module

When you add the Struts 2 facet to an existing module, IntelliJ IDEA downloads and adds the necessary libraries automatically.

The 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.

  1. Right-click the necessary module in the Project tool window and select Add Framework Support.

  2. Under the Java EE node, select Web Application .

    If you want the deployment descriptor web.xml file to be created, select the Create web.xml checkbox.

  3. Select the Struts 2 checkbox.

    You'll need a library that implements Struts 2. 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.

  4. Click OK.

The created Struts 2 configuration file struts.xml is located in the src node.

Define a validation file set

After you have enabled the Struts 2 support, IntelliJ IDEA automatically defines the validation list. You can edit it by adding, editing, and removing file sets.

Edit a validation file set

  1. From the main menu, select File | Project Structure Ctrl+Shift+Alt+S, and click Facets.

  2. Select the Struts 2 facet, select File Sets tab on the right, and click the Edit button.

    The Edit File Set dialog opens.

  3. To add files to the file set, select the checkboxes next the required files and click OK.

  4. To remove a file, select the file and click the Remove button

Remove a validation file set

To remove a validation file set, select it on the File Sets tab and click the Remove button.

Last modified: 20 September 2019