文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>mandriva tomcat配置

mandriva tomcat配置

时间:2009-04-18  来源:ybu2008

一、确认是否已经配置了JAVA的环境变量
   在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
tar xvfz jsvc.tar.gz
cd jsvc-src
autoconf
./configure
make
cp jsvc ..
cd ..

Tomcat can then be run as a daemon using the following commands.

 cd $CATALINA_HOME
./bin/jsvc -Djava.endorsed.dirs=./common/endorsed -cp ./bin/bootstrap.jar \
-outfile ./logs/catalina.out -errfile ./logs/catalina.err \
org.apache.catalina.startup.Bootstrap

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:

 Bootstrap
|
System
|
Common
/ \
Catalina Shared
/ \
Webapp1 Webapp2 ...

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:

  • Bootstrap - This class loader contains the basic runtime classes provided by the Java Virtual Machine, plus any classes from JAR files present in the System Extensions directory ($JAVA_HOME/jre/lib/ext). NOTE - Some JVMs may implement this as more than one class loader, or it may not be visible (as a class loader) at all.
  • System - This class loader is normally initialized from the contents of the CLASSPATH environment variable. All such classes are visible to both Tomcat internal classes, and to web applications. However, the standard Tomcat 5 startup scripts ($CATALINA_HOME/bin/catalina.sh or %CATALINA_HOME%\bin\catalina.bat) totally ignore the contents of the CLASSPATH environment variable itself, and instead build the System class loader from the following repositories:
    • $CATALINA_HOME/bin/bootstrap.jar - Contains the main() method that is used to initialize the Tomcat 5 server, and the class loader implementation classes it depends on.
    • $JAVA_HOME/lib/tools.jar - Contains the "javac" compiler used to convert JSP pages into servlet classes.
    • $CATALINA_HOME/bin/commons-logging-api-x.y.z.jar - Jakarta commons logging API.
    • $CATALINA_HOME/bin/commons-daemon.jar - Jakarta commons daemon API.
    • jmx.jar - The JMX 1.2 implementation.
  • Common - This class loader contains additional classes that are made visible to both Tomcat internal classes and to all web applications. Normally, application classes should NOT be placed here. All unpacked classes and resources in $CATALINA_HOME/common/classes, as well as classes and resources in JAR files under the $CATALINA_HOME/commons/endorsed, $CATALINA_HOME/commons/i18n and $CATALINA_HOME/common/lib directories, are made visible through this class loader. By default, that includes the following:
    • commons-el.jar - Jakarta commons el, implementing the expression language used by Jasper.
    • jasper-compiler.jar - The JSP 2.0 compiler.
    • jasper-compiler-jdt.jar - The Eclipse JDT Java compiler.
    • jasper-runtime.jar - The JSP 2.0 runtime.
    • jsp-api.jar - The JSP 2.0 API.
    • naming-common.jar - The JNDI implementation used by Tomcat 5 to represent in-memory naming contexts.
    • naming-factory.jar - The JNDI implementation used by Tomcat 5 to resolve references to enterprise resources (EJB, connection pools).
    • naming-factory-dbcp.jar - Jakarta commons DBCP, providing a JDBC connection pool to web applications. The classes have been moved out of their default org.apache.commons package.
    • naming-java.jar - Handler for the java: namespace.
    • naming-resources.jar - The specialized JNDI naming context implementation used to represent the static resources of a web application. This is not related to the support of the J2EE ENC, and cannot be removed.
    • servlet-api.jar - The Servlet 2.4 API.
    • tomcat-i18n-**.jar - Optional JARs containing resource bundles for other languages. As default bundles are also included in each individual JAR, they can be safely removed if no internationalization of messages is needed.
  • Catalina - This class loader is initialized to include all classes and resources required to implement Tomcat 5 itself. These classes and resources are TOTALLY invisible to web applications. All unpacked classes and resources in $CATALINA_HOME/server/classes, as well as classes and resources in JAR files under $CATALINA_HOME/server/lib, are made visible through this class loader. By default, that includes the following:
    • catalina.jar - Implementation of the Catalina servlet container portion of Tomcat 5.
    • catalina-ant.jar - Some Ant tasks which can be used to manage Tomcat using the manager web application.
    • catalina-optional.jar - Some optional components of Catalina.
    • commons-modeler.jar - A model MBeans implementation used by Tomcat to expose its internal objects through JMX.
    • servlets-xxxxx.jar - The classes associated with each internal servlet that provides part of Tomcat's functionality. These are separated so that they can be completely removed if the corresponding service is not required, or they can be subject to specialized security manager permissions.
    • tomcat-coyote.jar - Coyote API.
    • tomcat-http.jar - Standalone Java HTTP/1.1 connector.
    • tomcat-ajp.jar - Classes for the Java portion of the AJP web server connector, which allows Tomcat to run behind web servers such as Apache and iPlanet iAS and iWS.
    • tomcat-util.jar - Utility classes required by some Tomcat connectors.
  • Shared - This class loader is the place to put classes and resources that you wish to share across ALL web applications (unless Tomcat internal classes also need access, in which case you should put them in the Common class loader instead). All unpacked classes and resources in $CATALINA_BASE/shared/classes, as well as classes and resources in JAR files under $CATALINA_BASE/shared/lib, are made visible through this class loader. If multiple Tomcat instances are run from the same binary using the $CATALINA_BASE environment variable, then this classloader repositories are relative to $CATALINA_BASE rather than $CATALINA_HOME.
  • WebappX - A class loader is created for each web application that is deployed in a single Tomcat 5 instance. All unpacked classes and resources in the /WEB-INF/classes directory of your web application archive, plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application archive, are made visible to the containing web application, but to no others.

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:

  • Bootstrap classes of your JVM
  • System class loader classses (described above)
  • /WEB-INF/classes of your web application
  • /WEB-INF/lib/*.jar of your web application
  • $CATALINA_HOME/common/classes
  • $CATALINA_HOME/common/endorsed/*.jar
  • $CATALINA_HOME/common/i18n/*.jar
  • $CATALINA_HOME/common/lib/*.jar
  • $CATALINA_BASE/shared/classes
  • $CATALINA_BASE/shared/lib/*.jar
相关阅读 更多 +
排行榜 更多 +
修音音频剪辑

修音音频剪辑

图像拍照 下载
这都搞不定

这都搞不定

休闲益智 下载
精通学堂

精通学堂

学习教育 下载