Difference between revisions of "WTP Tomcat FAQ"
|Line 102:||Line 102:|
Revision as of 23:23, 19 November 2007
- 1 General
- 2 Getting Started
- 2.1 When I create a new Tomcat server, what should I know about its default configuration?
- 2.2 How does WTP support separate Tomcat server instances?
- 2.3 What are the advantages and disadvantages of using a separate Tomcat server instance?
- 2.4 What are the advantages and disadvantages of using the server instance from my Tomcat installation?
- 3 Information
- 3.1 How do I modify the Tomcat server's configuration?
- 3.2 How can I view or modify the launch configuration properties for a Tomcat server?
- 3.3 What configuration option determines whether the Tomcat server uses a separate instance or the instance from the Tomcat installation?
- 3.4 If my Tomcat server is using a separate instance, how do I find the location of this separate instance?
- 3.5 How do I find the location of the conf, logs, temp, webapps, and work directories for my Tomcat server?
- 3.6 When I create my first Tomcat server, why is a Servers project created in my workspace?
- 3.7 How do I determine which folder in the Servers project is associated with a particular Tomcat server?
- 3.8 What does Publish do for Tomcat servers in the Servers view?
- 3.9 Why are <Context> elements added to server.xml when Dynamic Web Projects are added to the Tomcat server?
- 3.10 How do I specify the Tomcat context configuration for my Web Application?
- 3.11 How do I make the Servlet and JSP API Javadoc in my Tomcat installation accessible within Eclipse?
- 3.12 How do I enable the JULI logging in a Tomcat 5.5 Server instance?
- 4 Trouble Shooting
What should I know about this FAQ?
This FAQ includes frequently asked questions and other useful information about the support for Apache Tomcat servers in WTP 1.5.x (WTP 2.0 information will be added later). The answers below assume some familiarity with your Tomcat version and its configuration. The answers are not intended to educate you about Tomcat to any significant degree. Covered is Tomcat v4.0 through v5.5. Tomcat v6.0 is not supported by WTP 1.5.x. Tomcat 3.2 is omitted since it differs significantly from the other Tomcat versions and is not likely to have enough users to make its inclusion worth the effort.
You are encouraged to review the questions and answers in the Getting Started section for some important background information.
When I create a new Tomcat server, what should I know about its default configuration?
When you create a new Tomcat server in Eclipse, the New Server wizard assumes it is not safe to affect the current behavior of the Tomcat installation that this new server will use. This is achieved by using Tomcat's ability to run multiple server instances from a single installation. Thus, the default configuration for each new Tomcat sever you create will be a new server instance of the Tomcat installation associated with the Tomcat runtime selected in the wizard. If you expecte the new Tomcat server in Eclipse to run the same instance that the default batch files in your Tomcat installation run, you will likely be surprised when the Tomcat server in Eclipse doesn't behave as expected.
The Tomcat server configuration can be changed so that it does run the same instance as your Tomcat installation. However, there are advantages and disadvantages to doing this, which should be reviewed before making this configuration change. This is addressed by the remaining Getting Started questions.
How does WTP support separate Tomcat server instances?
Apache Tomcat 4.0 and later operate with paths that are relative to one of two locations. These two locations are known in the Tomcat batch scripts as CATALINA_HOME and CATALINA_BASE. In the Java command that actually runs Tomcat, they appear as catalina.home and catalina.base system properties. The "home" location defines where the binary portion of Tomcat lives. This includes the bin, common, and server directories. The "base" location defines where the configuration and working directories for a Tomcat server instance lives. This includes the conf, logs, shared, webapps, and work directories. Tomcat servers created in WTP will have their "home" location set to the Tomcat installation associated with the Tomcat Runtime selected for the server. The "base" location will default to an internally created directory under the .metadata folder found in your workspace.
What are the advantages and disadvantages of using a separate Tomcat server instance?
The main advantage is that configuration changes you make to your Tomcat server within WTP will have no effect on the behavior of the server configured in your Tomcat installation, assuming that is desired. You can run them simultaneously provided the port numbers used by the servers are modified to avoid conflicts. Also, when using a separate instances, you have the option of creating multiple servers from a single Tomcat installation. If you have web projects or testing that need different server environments, you can create and configure a separate server for each of these environments. This will be less error prone than reconfiguring a single server between the various environments.
The main disadvantage is that the standard web applications that come with Tomcat don't automatically appear. However, they can be added manually, if needed, and save a little start-up time for those web applications that are not needed. Another disadvantage is that your Dynamic Web Projects are not automatically served when you start your Tomcat installation's server instance, assuming that is desired. You have to manually deploy them to the Tomcat installation first. Depending on how your installation's Tomcat server is configured, this could be as simple as exporting the Web project as a War file and writing that file to the server's webapps folder.
What are the advantages and disadvantages of using the server instance from my Tomcat installation?
The main advantage of using the server instance from your Tomcat installation is that you can run the same server outside of Eclipse that you run inside of Eclipse. In addition, the web applications that come standard with Tomcat are present automatically.
The main disadvantage with this configuration is that the Tomcat server in Eclipse, in a sense, owns the Tomcat installation. The files found in the associated subfolder under the Servers project in your workspace become the master versions of these Tomcat configuration files. Each time you start this Tomcat server in Eclipse, those files will overwrite the corresponding files in the Tomcat installation. Any changes made locally to those files in the installation would be lost. This implies there will be problems trying to make permanent changes to the Tomcat server using the Manager or Admin Web applications available for Tomcat.
An additional disadvantage is that any custom options added to the Tomcat server's launch configuration within Eclipse will need to be duplicated in the Tomcat batch scripts if the Tomcat server is to be run outside of Eclipse.
How do I modify the Tomcat server's configuration?
The Tomcat server's configuration can be changed using the server editor. This editor is opened by displaying the context menu for the server in the Servers view and selecting Open. Double-clicking on the server in the Servers view also opens this editor. The editor contains two views, Overview and Modules, which display different portions of the Tomcat configuration. You switch between these views by clicking on their respective tabs at the bottom of the editor.
The configuration for a Tomcat server includes a number of WTP specific options and settings, shown in the Server and Automatic Publishing sections of the Overview view. More importantly, it also includes the set of Tomcat configuration files found in the folder specified by the Configuration Path field shown in the General section of this view. This server editor has the ability to make a limited set of modifications to the server.xml in that folder, such as modifying the server port numbers. Modifications to the other files and other modifications to server.xml will need to be made directly to the file.
The Modules view displays the contexts that the Tomcat server is configured to server. These contexts include Dynamic Web Projects that have been added to the server as well as contexts manually added using this view.
As a convenience, the launch configuration Properties dialog for the Tomcat server may be opened from the Overview view of the server editor by clicking on the Open launch configuration link found in the General section.
How can I view or modify the launch configuration properties for a Tomcat server?
The Java start-up environment for a Tomcat server is displayed in the launch configuration Properties dialog for the server. The most straightforward way to open this dialog is to first open the server editor for the Tomcat server. Once the server editor is open, click the Open launch configuration link found in the General section of the Overview view. This approach has the advantage of creating the launch configuration if it is a new server that has not yet been started for the first time. You can also open the launch configuration Properties dialog by executing Run -> Run... (or Debug...) and select the desired run configuration from those under the Apache Tomcat category.
What configuration option determines whether the Tomcat server uses a separate instance or the instance from the Tomcat installation?
The Run modules directly from the workspace (do not modify the Tomcat installation) checkbox of the server editor controls this option. It is found in the General section of the Overview view. If checked, a separate instance is used. If not checked, the instance from the Tomcat installation is used. The default is checked. It is best to change this option immediately after creating the server, or at least while no projects have been added to the server.
If my Tomcat server is using a separate instance, how do I find the location of this separate instance?
The best way to find the instance location, known as CATALINA_BASE in the Tomcat batch scripts, is to first open the launch configuration Properties dialog. Then select the Arguments tab in this dialog and examine the contents of the VM Arguments field. The value for the catalina.base system property specifies the instance location
How do I find the location of the conf, logs, temp, webapps, and work directories for my Tomcat server?
The conf, logs, temp, webapps, and work directories are all relative to the Tomcat server's instance location, known as CATALINA_BASE to the batch files. To find this location, see the previous question.
When I create my first Tomcat server, why is a Servers project created in my workspace?
The Servers project is created, along with a subfolder associated with the Tomcat server, to hold copies of the server.xml, catalina.policy, tomcat-users.xml, and web.xml files for that Tomcat server. This makes is easier to make modifications to those files. It also allows these files to be "working copies", separate from the copies that are found in the conf directory of the instance location. This avoids the possibility of interfering with a running Tomcat server if modifications are made to the files in the Servers project while the server is running.
This Servers project must remain open for Tomcat servers to function properly. Be aware that use of the Close Unrelated Projects command may unintentionally close the Servers project. Reopen the Servers project if this occurs.
How do I determine which folder in the Servers project is associated with a particular Tomcat server?
From the Servers view, open the server editor for the desired Tomcat server. In the General section of the Overview view, the Configuration path field displays the path to the associated folder in the workspace that contains the Tomcat configuration files. The default name for this folder is the name of the server with "-config" appended.
What does Publish do for Tomcat servers in the Servers view?
Publish updates the server instance with any server configuration changes, changes related to projects added or removed from the server, and content changes in projects already added to the server. This includes copying the server configuration files found under the associated subfolder of the Servers project to the server's instance location. In the case of server.xml, "adjustments" may be made to the file by WTP during the copy. For an example of an "adjustment", see this question.
Note the configuration files under the subfolders in the Servers project are not used directly by running servers. The running server uses copies of these files. This implies that any manual changes made to the copy will be overwritten the next time the server is published.
Also note that all files found in the subfolder of the Servers project will be copied. If you have imported additional files there, such as catalina.properties or logging.properties, they will be available to the running server in its conf directory.
Why are <Context> elements added to server.xml when Dynamic Web Projects are added to the Tomcat server?
Though the approach of declaring contexts by adding <Context> elements to server.xml has been deprecated in current Tomcat versions, it is still the only approach that works across all Tomcat versions. In addition, the handling for these <Context> elements is consistent across all Tomcat versions. The support for individual context XML files is not supported for Tomcat 3.2 and varies between the remaining Tomcat versions.
How do I specify the Tomcat context configuration for my Web Application?
The configuration within <Context> elements may be added to the server.xml file associated with the Tomcat server, after the project has been added to the server. Note that if the project is removed from the server, this configuration will be lost. You can save a copy of the configuration in some file in your project if you want to persist this information.
Another approach is use the support found in Tomcat 4.1 and later for specifying context configuration within a META-INF/context.xml file found in the Web application. If a project containing a META-INF/context.xml file is added to one of these Tomcat servers in WTP, the context configuration found in this file will be included in the server.xml when this file copied as part of publishing the server. When adding the configuration from the META-INF/context.xml file, all child elements of the <Context> are copied as well as its attributes, excluding path and docBase.
How do I make the Servlet and JSP API Javadoc in my Tomcat installation accessible within Eclipse?
The tomcat-docs Web application that comes in the standard Tomcat installation includes Javadoc for the servlet and JSP API classes. It is possible to attach this Javadoc to the appropriate JAR(s) in a Tomcat runtime and receive the benefits supported by Eclipse. Other Javadoc and source you acquire for the Tomcat runtime JARs can also be attached in a similar fashion. Caching of this information means that you only have to specify this once per Tomcat runtime in each workspace you use. You do not have to do it for each project.
- If you do not have one already, create a Dynamic Web Project which uses the Tomcat runtime to which you want to attach the Servlet and JSP API Javadoc.
- In the Package Explorer view, expand the Dynamic Web Project and its library folder for the Tomcat runtime.
- Right-click the API JAR (see table that follows) and select Properties.
- In the Properties dialog, select Javadoc Location in the tree on the left.
- With the Javadoc URL option selected, click Browse. Navigate to the appropriate folder (see table that follows) and click OK twice to exit the Properties dialog.
The JAR name and folder varies depending on the version of Tomcat. The following table gives the various choices.
|Tomcat Version||API||JAR||tomcat-docs Subfolder|
|4.x||Servlet & JSP||servlet.jar||servletapi|
How do I enable the JULI logging in a Tomcat 5.5 Server instance?
Tomcat 5.5 comes with an enhanced implementation of java.util.logging, called JULI, which is configured by default in a standard Tomcat 5.5 installation. This JULI logging configuration is not picked up automatically when creating a new Tomcat 5.5 server in WTP. Some manual steps are necessary to add this configuration to your WTP Tomcat 5.5 server.
- Open the server editor for the Tomcat server and note the folder specified by the Configuration path field.
- Import the logging.properties file from the conf directory of your Tomcat 5.5 installation into this folder in your workspace.
- In the server editor, click on the Open launch configuration link and in the launch configuration Properties dialog, switch to the Arguments tab.
- In the VM Arguments field, add the following two system properties substituting the catalina.base path where noted:
-Djava.util.logging.config.file="<put catalina.base path here>/conf/logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
The imported logging.properties file can be used to control the JULI logging configuration for the Tomcat server.