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).
 |
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:
- In the Projects window, right-click the project's node and choose Properties.
- In the Project Properties dialog box, click the Packaging node in the left
pane.
- Add the necessary resources to the web application by clicking
the appropriate button. You can add any of the following:
- Project. The JAR file or
WAR file produced by another project.
- Library. A collection of JAR
files or folders with compiled classes.
If the library
is not available, click Add Library, then click Manage Libraries, and create a new library entry for your
library. Alternatively, you can access the Library Manager by choosing Tools > Library Manager in the main menubar.
- JAR/Folder. A JAR file or folder somewhere on your system.
- Click Add and
repeat as needed. To remove an added file, select the file in the
list and click Remove.
- (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).
- 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.
- 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