mandriva tomcat配置
时间:2009-04-18 来源:ybu2008
在bash能够识别java命令,并不代表已经配置好JAVA_HOME等环境变量。编辑/etc/profile
加入:
JAVA_HOME=/usr/lib/jvm/java
export JAVA_HOME
二、在mandirva下使用命令urpmi安装tomcat5,安装的默认路径为/usr/share/tomcat5
配置其目录conf/tomcat5.conf(tomcat5好像是以profile中的环境变量为准,在没有配置JAVA环境变量时,tomcat5是以java启动命令所在的目录为JAVA_HOME,即/usr/bin,所以必须先配置好JAVA环境变量)。然后在/etc/profile中添加:
CATALINA_BASE=/usr/share/tomcat5
export CATALINA_BASE
CATALINA_HOME=/usr/share/tomcat5
export CATALINA_HOME
在这里,不知为什么,如果没有在profile中加入CATALINA的环境变量,而是修改tomcat5.conf的CATALINA_BASE和CATALINA_HOME,tomcat5依然没法运行。
注意CATALINA_HOME/workers.properties的worker.inprocess.jvm_lib值,默认是使用windows下的设置,要改为自己的平台,同时,检查路径是否正确。对于amd64平台,libjvm.so是在workers.java_home/jre/lib/amd64/server/下。
根据自己java和tomcat安装的路径去检查tomcat5.conf、workers.properties和catalina.conf的配置有没有错误。
如果在启动不了,可以使用tomcat5 debug命令,然后输入run,去逐一检查。
三、在启动过程中遇到的错误
1、VM 启动异常: VM initialization failed for: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java。主要是没有打开lo接口,在bash输入ifconfig lo up可解决。
2、
java.lang.ClassNotFoundException: org.apache.catalina.startup.Catalina
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:198)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:386)
主要原因是CATALINA_HOME环境没有配置好,尝试在profile配置。
四、tomcat介绍(以下转自:http://tomcat.apache.org)
Unix daemon
Tomcat can be run as a daemon using the jsvc tool from the commons-daemon project. Source tarballs for jsvc are included with the Tomcat binaries, and need to be compiled. Building jsvc requires a C ANSI compiler (such as GCC), GNU Autoconf, and a JDK.
Before running the script, the JAVA_HOME environment variable should be set to the base path of the JDK. Alternately, when calling the ./configure script, the path of the JDK may be specified using the --with-java parameter, such as ./configure --with-java=/usr/java.
Using the following commands should result in a compiled jsvc binary, located in the $CATALINA_HOME/bin folder. This assumes that GNU TAR is used, and that CATALINA_HOME is an environment variable pointing to the base path of the Tomcat installation.
Please note that you should use the GNU make (gmake) instead of the native BSD make on FreeBSD systems.
![]() |
![]() |
![]() |
![]() |
cd $CATALINA_HOME/bin |
![]() |
![]() |
![]() |
![]() |
Tomcat can then be run as a daemon using the following commands.
![]() |
![]() |
![]() |
![]() |
cd $CATALINA_HOME |
![]() |
![]() |
![]() |
![]() |
jsvc has other useful parameters, such as -user which causes it to switch to another user after the daemon initialization is complete. This allows, for example, running Tomcat as a non privileged user while still being able to use privileged ports. jsvc --help will return the full jsvc usage information. In particular, the -debug option is useful to debug issues running jsvc.
The file $CATALINA_HOME/bin/jsvc/native/tomcat.sh can be used as a template for starting Tomcat automatically at boot time from /etc/init.d. The file is currently setup for running Tomcat 4.1.x, so it is necessary to edit it and change the classname from BootstrapService to Bootstrap.
Note that the Commons-Daemon JAR file must be on your runtime classpath to run Tomcat in this manner. The Commons-Daemon JAR file is in the Class-Path entry of the bootstrap.jar manifest, but if you get a ClassNotFoundException or a NoClassDefFoundError for a Commons-Daemon class, add the Commons-Daemon JAR to the -cp argument when launching jsvc.
Overview | |||||||||
Like many server applications, Tomcat 5 installs a variety of class loaders (that is, classes that implement java.lang.ClassLoader) to allow different portions of the container, and the web applications running on the container, to have access to different repositories of available classes and resources. This mechanism is used to provide the functionality defined in the Servlet Specification, version 2.4 -- in particular, Sections 9.4 and 9.6. In a J2SE 2 (that is, J2SE 1.2 or later) environment, class loaders are arranged in a parent-child tree. Normally, when a class loader is asked to load a particular class or resource, it delegates the request to a parent class loader first, and then looks in its own repositories only if the parent class loader(s) cannot find the requested class or resource. The model for web application class loaders differs slightly from this, as discussed below, but the main principles are the same. When Tomcat 5 is started, it creates a set of class loaders that are organized into the following parent-child relationships, where the parent class loader is above the child class loader:
The characteristics of each of these class loaders, including the source of classes and resources that they make visible, are discussed in detail in the following section. |
Class Loader Definitions |
As indicated in the diagram above, Tomcat 5 creates the following class loaders as it is initialized:
As mentioned above, the web application class loader diverges from the default Java 2 delegation model (in accordance with the recommendations in the Servlet Specification, version 2.3, section 9.7.2 Web Application Classloader). When a request to load a class from the web application's WebappX class loader is processed, this class loader will look in the local repositories first, instead of delegating before looking. There are exceptions. Classes which are part of the JRE base classes cannot be overriden. For some classes (such as the XML parser components in J2SE 1.4+), the J2SE 1.4 endorsed feature can be used (see the common classloader definition above). Last, any JAR containing servlet API classes will be ignored by the classloader. All other class loaders in Tomcat 5 follow the usual delegation pattern. Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:
|