NetBeans-SCSNI

4.5-Demonstrate a knowledge of basic tasks related to building and deploying web applications to a server, such as changing the target server and undeploying an application.

About Building Web Applications

The IDE uses an Ant build script to build your web applications. If you are using a standard project , the IDE generates the build script based on the options you enter in the project's Project Properties dialog box. You can set the project's classpath, context path, and web server in the Project Properties dialog box. You can further customize program execution by editing the Ant script and Ant properties for the project.

If you are using a free-form project , the IDE uses your existing Ant script to build your project. You can write a target that builds the currently selected project in the IDE and map it to the Build command.

With standard web projects, you can customize the build process by doing any of the following:

  • Enter basic options, like classpath settings, packaging settings, and WAR filters, in the Project Properties dialog box.
  • Specify that all JSP files in the project must be compiled during the build. 
By default, the IDE does not compile JSP files while building a project. This is because JSP compilation can take a long time because JSP files have to be translated to servlets before they can be compiled. However, if you do not have too many JSP files or if you want them to be compiled anyway, right-click the project node in the Projects window, choose Properties, click Compiling, and select the Test compile all JSP files during builds checkbox.
  • Customize the IDE-generated Ant targets or create new targets in build.xml.
  • Edit properties in project.properties to change the name and location of build output folders and files.         

Deploying a Web Application

When you run a web application, the IDE automatically builds, deploys, and executes the web application using the project's target server. By default, the index.jsp file is displayed as the welcome file when the application is launched.

To deploy a web application:

  1. (Optional) Define parameters to pass to one or more JSP files, servlets, or both.
  2. (Optional) Specify a different welcome file by right-clicking the project node in the Projects window, choosing Properties, clicking Run, and typing it in the Relative URL text box.
    •   The welcome file specified in the Project Properties dialog box overrides the welcome file set in the web.xml file. If no welcome file is defined in the Project Properties dialog box, the first existing welcome file defined in the web.xml file's welcome-file-list is displayed. If the server does not find a welcome file, the server's default servlet displays the root of the web application. You can change the behavior of the default servlet in the web.xml file.
  3. (Optional) Specify a different target server or browser.
  4. In the Projects window, right-click the project's node and choose Run.
The IDE sends the web application's URL to the server. The URL is derived from the server's URL, the web application's context path, and the relative URL or welcome file. The first time you deploy an application per session to the Tomcat Web Server, you need to authenticate yourself.

Troubleshooting

The Output window displays error information and the HTTP monitor displays requests, data states, and the servlet environment.

  • If you get "file not found" errors when you execute a web application, see Accessing Local files Through a Proxy for possible solutions.
  • If you get an error message indicating that a resource is not available, check to verify the following:
    • The URL is correct.
    • The servlet mapping in the web.xml file is correct.
    • The application's resources are in the appropriate location.

Changing the Target Server

Each project has a target server. The target server is the server that is used when the project is run. You can set the target server to any server which has been registered in the IDE.

To change the target server:

  1. Right-click the project node in the Projects window and choose Properties.
  2. Select Run in the Project Properties dialog box.
  3. Select the new target server from the Server drop-down menu and click OK.

-- Wagner R. Santos