Packaging a Resource in a WAR File

See Also

When you package a web application as a WAR file, the default package includes only those files that are part of the web application. To add a file that is external to the web application to the WAR package, use the Project Properties dialog box. Extra files might include applets, image files, text files, or other resources that reside outside the web application. When adding extra files, the default target folder is the web application's document base (root folder).

tip If you use the instructions below to package a resource in the web application, you will not add it to the classpath. For example, tag libraries need to be added to the classpath for code completion to work. To add a resource to the classpath, see Managing the Classpath.

To package a resource in a WAR file:

  1. In the Projects window, right-click the project's node and choose Properties.
  2. In the Project Properties dialog box, click the Packaging node in the left pane.
  3. Add the necessary resources to the web application by clicking the appropriate button. You can add any of the following:
  4. Click Add and repeat as needed. To remove an added file, select the file in the list and click Remove.
  5. (Optional) Type a location for the resource in the table's Path in WAR column. By default, the resource will be copied to the web application's document root, which is the build/web folder (the highest level of the web application's file structure).
  6. Click OK to close the Project Properties dialog box. When you build the project, the IDE packages your resource in the project's WAR file and includes it in the build/web folder.

    After adding a resource to a WAR file, you may need to do some post-processing. For example, when you add a servlet you must manually register it in the web application's web.xml file (the web application's deployment descriptor). You can use the web.xml Visual Editor to do so. Note that when you create a servlet using the New File wizard, the IDE handles this task for you.

  7. Test the availability of the added resource. For example, if you have added an applet to the WAR file, define it in a JSP file.
See Also
About Building Web Applications
Building a WAR File

Legal Notices