Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C283A8870 for ; Wed, 10 Aug 2011 17:42:31 +0000 (UTC) Received: (qmail 73950 invoked by uid 500); 10 Aug 2011 17:42:30 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 73820 invoked by uid 500); 10 Aug 2011 17:42:30 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 73802 invoked by uid 99); 10 Aug 2011 17:42:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Aug 2011 17:42:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.131] (HELO eos.apache.org) (140.211.11.131) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Aug 2011 17:42:27 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id 21AB425B; Wed, 10 Aug 2011 17:42:07 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Apache Wiki To: Apache Wiki Date: Wed, 10 Aug 2011 17:42:06 -0000 Message-ID: <20110810174206.33649.22219@eos.apache.org> Subject: =?utf-8?q?=5BTomcat_Wiki=5D_Update_of_=22HowTo=22_by_DomaLajos?= Auto-Submitted: auto-generated Dear Wiki user, You have subscribed to a wiki page or wiki category on "Tomcat Wiki" for ch= ange notification. The "HowTo" page has been changed by DomaLajos: http://wiki.apache.org/tomcat/HowTo?action=3Ddiff&rev1=3D111&rev2=3D112 = ---- =3D Meta =3D - = =3D=3D How do I add a question to this page? =3D=3D Anyone may edit this page to add their own content. That is why this page= is part of a Wiki and not a hardcoded static file in the FAQ. = However, ''do not'' add questions without answers to this page. If you ha= ve a question about how to do something in Tomcat which has not been addres= sed yet, ask the [[http://tomcat.apache.org/lists.html#tomcat-users|tomcat-= user list]]. Once you've figured out how to fix your problem, come back and= update the Wiki to allow the rest of us to benefit from what you've learne= d! = =3D=3D How do I contribute to Tomcat's documentation? =3D=3D - = Download the source bundle or grab the source XML file from [[http://tomc= at.apache.org/svn.html|Subversion repository]]. If you are not familiar wit= h Subversion, see http://www.apache.org/dev/contributors.html. = The docs are in the webapps/docs subdirectory. They are in XML format an= d get processed into the HTML documentation as part of the Tomcat release. @@ -26, +24 @@ = ---- =3D Installation =3D - = =3D=3D How do I set up and run Tomcat on Macintosh OS X? =3D=3D See [[TomcatOnMacOS]] = =3D=3D How do I set up and run Tomcat on Solaris 10? =3D=3D See TomcatOnSolaris10 = - = =3D=3D How do I set up another tomcat service on Windows, sharing the sam= e Tomcat Home ? =3D=3D This script sets up a a tomcat base directory and calls tomcat5.exe to cr= eate a windows service which will use the tomcat home given for the binarie= s and tomcat base you create See TomcatCreateWindowsService = @@ -48, +44 @@ = . (!) It also makes a lot of sense to use the JavaServiceWrapper. = - = =3D=3D How to run Tomcat without root privileges? =3D=3D The best way is to use jsvc, available as part of the [[http://commons.ap= ache.org/daemon/jsvc.html|commons-daemon]] project. = @@ -99, +94 @@ {{{ sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in }}} - = - = ---- + Yet another way is to use authbind (part of Debian- and CentOS based dist= ributions) which allows a program that would normally require superuser pri= vileges to access privileged network services to run as a non-privileged us= er. The article at http://java-notes.com/index.php/installing-tomcat-with-h= ttp-port-80-on-linux discusses how to install and configure the authbind pa= ckage with Tomcat 6.0 on Linux. + = =3D Configuration =3D - = =3D=3D How do I set up multiple sites sharing the same war application/wa= r file? =3D=3D See CreateVirtualHosts = @@ -256, +250 @@ = 1. Now when you visit ''http://localhost:8080/admin'' you should see a p= age that asks for a user name and password. If you still see the "no longe= r loaded" error message in your browser, you must either force a full reloa= d of the web page (in Firefox, hold down Shift key while clicking on the Re= load button) or just restart your browser completely. = - = =3D=3D How do I add JARs or classes to the common classloader without add= ing them to $CATALINA_HOME/lib? =3D=3D - = Either = a) Run Tomcat with separate {{{$CATALINA_BASE}}} and {{{$CATALINA_HOME}}}= (as documented in {{{RUNNING.txt}}}) and place those classes into {{{$CATA= LINA_BASE/lib}}}, or @@ -332, +324 @@ =3D=3D How do I set up Tomcat virtual hosts in a development environment?= =3D=3D See TomcatDevelopmentVirtualHosts = - = ---- =3D Programming =3D - = =3D=3D How do call tomcat ant tasks to deploy webapps? =3D=3D See AntDeploy = @@ -385, +375 @@ p.load(is); is.close(); }}} - = =3D=3D How do I share sessions across web apps? =3D=3D You cannot share sessions directly across web apps, as that would be a vi= olation of the Servlet Specification. There are workarounds, including usi= ng a singleton class loaded from the common classloader repository to hold = shared information, or putting some of this shared information in a databas= e or another data store. Some of these approaches have been discussed on t= he [[http://tomcat.apache.org/lists.html#tomcat-users|tomcat-user mailing l= ist]], whose archives you should search for more information. = @@ -460, +449 @@ Context context =3D (Context) host.findChild("myContext"); Realm realm =3D context.getRealm(); }}} - = =3D=3D How do I redirect System.out and System.err to my web page? =3D=3D I have met a situation where I needed to redirect a portion of standard o= uput (`System.out`, STDOUT) and standard error (`System.err`, STDERR) to my= web page instead of a log file. An example of such an application is a com= piler research platform that our resarch team is putting online for anybody= to be able to quickly compile-test their programs on line. Naturally, the = compilers dump some of their stuff to STDERR or STDOUT and they are not web= application `.jar`. Thus, I needed badly these streams related to the comp= iler output to be redirected to my web editor interface. Having found no ea= sy instructions on how to do that lead me writing up this quick HOWTO. The = HOWTO is based on Servlets, but similar arrangements can be done for JSPs. = The below example shows the essentials, with most non-essentials removed. = @@ -624, +612 @@ = ---- =3D Troubleshooting =3D - = =3D=3D Tomcat crashed! What do I do now? =3D=3D These steps are in no particular order ... = @@ -641, +628 @@ 1. Using a database? Make sure JDBC type 4 drivers are used. Check their= release notes. 1. Tweak JVM memory parameters. Setting memory too high can be as bad as= having memory too low. If your memory settings are set too high, Java 1.3 = JVMs may freeze while waiting for the entire garbage collection to finish. = Also if the JVM has too much memory, if may be starving other resources on = the machine which are needed which may be causing unforeseen exceptions. In= a nutshell, throwing more memory doesn't always solve the problem! 1. Turn off the Java JIT compiler. See the Java Docs on how to do this. - = = =3D=3D I'm encountering classloader problems when using JNI under Tomcat = =3D=3D The important thing to know about using JNI under Tomcat is that one cann= ot place the native libraries OR their JNI interfaces under the WEB-INF/lib= or WEB-INF/classes directories of a web application and expect to be able = to reload the webapp without restarting the server. The class that calls Sy= stem.loadLibrary(String) must be loaded by a classloader that is not affect= ed by reloading the web application itself. @@ -886, +872 @@ } } }}} - = =3D=3D How do I obtain a thread dump of my running webapp ? =3D=3D You can only get a thread dump of the entire JVM, not just your webapp. T= his shouldn't be a big deal, but should be made clear: you are getting a du= mp of all JVM threads, not just those "for your application", whatever that= means. = @@ -911, +896 @@ = This will produce a thread dump on standard output, but may not be possib= le to capture to a file. = - = =3D=3D How do I add my own custom MBean to monitor my application within = Tomcat 5/6? =3D=3D - = - First of all, you can read [[http://oss.wxnet.org/mbeans.html|this great = tutorial]] from Christopher Blunck (chris@wxnet.org). + First of all, you can read [[http://oss.wxnet.org/mbeans.html|this great = tutorial]] from Christopher Blunck ( chris@wxnet.org ). I will just add my = comments and improvements. - I will just add my comments and improvements. = + 1. Start your Tomcat and check that you have access to http://localhost:8= 080/manager/jmxproxy/. It means that JMX is enabled on your Tomcat configur= ation (if not, check if the following line is in your /conf/server.xml file= : ''''. Otherwise, check the Tomcat documentation to activate it). Let= this page opened to check further if your custom Mbean is detected by Tomc= at.<
> - 1. Start your Tomcat and check that you have access to [[http://localhost= :8080/manager/jmxproxy/]]. It means that JMX is enabled on your Tomcat conf= iguration (if not, check if the following line is in your /conf/server.xml = file : = - ''''. Otherwise, check the Tomcat documentation to activate it). - Let this page opened to check further if your custom Mbean is detected by= Tomcat.<
> = - 2. Build your custom MBean by following the Christopher Blunck's example = : <
> + 2. Build your custom MBean by following the Christopher Blunck's example = : <
> '''ServerMBean.java''' : - '''ServerMBean.java''' : = + = {{{ package org.wxnet.mbeans; = @@ -931, +911 @@ public long getUptime(); } }}} - '''Server.java''' : = + '''Server.java''' : + = {{{ package org.wxnet.mbeans; = @@ -973, +954 @@ System.out.println("Found our MBean server"); } else { mbserver =3D MBeanServerFactory.createMBeanServer(); - } = + } = return mbserver; } @@ -984, +965 @@ public long getUptime() { return System.currentTimeMills() - _startTi= me; } } }}} + In this implementation, firstly notice the ''ObjectName'' representing th= e MBean (in the constructor) : ''name =3D new ObjectName("'''Application'''= :Name=3D'''Server''',Type=3D'''Server'''");'' Do not hesitate to change the= domain name (the first parameter) by your own to easily find your MBean re= ference in the http://localhost:8080/manager/jmxproxy page.<
> Secondly,= take a look at your MBean constructor : <
> - In this implementation, firstly notice the ''ObjectName'' representing th= e MBean (in the constructor) : ''name =3D new ObjectName("'''Application'''= :Name=3D'''Server''',Type=3D'''Server'''");'' - Do not hesitate to change the domain name (the first parameter) by your o= wn to easily find your MBean reference in the [[http://localhost:8080/manag= er/jmxproxy]] page.<
> - Secondly, take a look at your MBean constructor : <
> - a. First step is to get a reference to the Tomcat's MBeanServer with ''M= BeanServer server =3D getServer();''.<
> - b. The ''getServer()'' method returns the default Tomcat's MBean server.= <
> = - A good question right now could be : what happens if I decide to create m= y own MBeanServer? The answer is very simple : '''nothing'''.<
> - After many research in the (empty) Tomcat's documentation and on the inte= rnet, after many tests, I conclued that you can't create your custom MBean = server. More precisely, you can create it but Tomcat won't keep any referen= ce to it.<
> - You can replace the previous ''getServer()'' method by this one to test: = {{{ + a. First step is to get a reference to the Tomcat's MBeanServer with ''M= BeanServer server =3D getServer();''.<
> b. The ''getServer()'' method r= eturns the default Tomcat's MBean server.<
> + = + A good question right now could be : what happens if I decide to create m= y own MBeanServer? The answer is very simple : '''nothing'''.<
> After m= any research in the (empty) Tomcat's documentation and on the internet, aft= er many tests, I conclued that you can't create your custom MBean server. M= ore precisely, you can create it but Tomcat won't keep any reference to it.= <
> You can replace the previous ''getServer()'' method by this one to t= est: + = + {{{ private MBeanServer getServer() { MBeanServer mbserver =3D null; = MBeanServer myMBServer =3D MBeanServerFactory.createMBeanServer("= myMBServer"); - = + = ArrayList mbservers =3D MBeanServerFactory.findMBean= Server(null); System.out.println("****** TOMCAT'S LIST OF REGISTERED MBEANSERVE= RS ********** "); System.out.println(mbservers.toString()); - = + = System.out.println("****** TRYING TO RETRIEVE MY OWN MBEANSERVER = FROM ITS AgentId ********** "); ArrayList mbservers_2 =3D MBeanServerFactory.findMBe= anServer("myMBServer"); System.out.println(mbservers_2.toString()); - = - = + = + = if (mbservers.size() > 0) { mbserver =3D (MBeanServer) mbservers.get(0); } @@ -1020, +999 @@ return mbserver; } }}} + Here is a capture of the println() : https://picasaweb.google.com/lh/phot= o/jzVX9-NBGwF57A0m8qqv2Q?feat=3Ddirectlink. Tomcat seems to register 2 Mbea= n server but when I try to fetch mine from its AgentId (here "myMBServer"),= nothing is found. In my opinion, Tomcat might re-implement the ''MBeanServ= erFactory'' java class to control the server creation. Then, it doesn't kee= p a reference to the newly created MBean server. Moreover, if Tomcat re-imp= lement the MBeanFactory class, there is no method to directly add MBean (se= e the http://tomcat.apache.org/tomcat-6.0-doc/api/index.html).<
> - Here is a capture of the println() : [[https://picasaweb.google.com/lh/ph= oto/jzVX9-NBGwF57A0m8qqv2Q?feat=3Ddirectlink]]. - Tomcat seems to register 2 Mbean server but when I try to fetch mine from= its AgentId (here "myMBServer"), nothing is found. - In my opinion, Tomcat might re-implement the ''MBeanServerFactory'' java = class to control the server creation. Then, it doesn't keep a reference to = the newly created MBean server. Moreover, if Tomcat re-implement the MBeanF= actory class, there is no method to directly add MBean (see the [[http://to= mcat.apache.org/tomcat-6.0-doc/api/index.html||Tomcat's javadoc]]).<
> = - In my application architecture, I placed the 2 MBeans files (the interfac= e and its implementation) in a particular package (I don't think its compul= sary but definitely more aesthetic). + In my application architecture, I placed the 2 MBeans files (the interfac= e and its implementation) in a particular package (I don't think its compul= sary but definitely more aesthetic). Compile those one in a jar archive and= place it in the Tomcat's library folder (/lib).<
> - Compile those one in a jar archive and place it in the Tomcat's library f= older (/lib).<
> = - 3. Build your '''ContextListener''' : According to the [[[[http://tomcat.= apache.org/tomcat-6.0-doc/config/listeners.html|Tomcat's documentation]], a= Listener is a ''a component that performs actions when specific events occ= ur, usually Tomcat '''starting''' or Tomcat stopping.''. + 3. Build your '''ContextListener''' : According to the [[[[http://tomcat.= apache.org/tomcat-6.0-doc/config/listeners.html|Tomcat's documentation]], a= Listener is a ''a component that performs actions when specific events occ= ur, usually Tomcat '''starting''' or Tomcat stopping.''. We need to instant= iate and load our MBean at Tomcat's start. So we build a ContextListener.ja= va file which is placed wherever you want in your project architecture : - We need to instantiate and load our MBean at Tomcat's start. So we build = a ContextListener.java file which is placed wherever you want in your proje= ct architecture : = + = {{{ package '''org.bonitasoft.context'''; = @@ -1053, +1029 @@ = } }}} - Take a look especially at the contextInitialized method. It just instanti= ates our custom MBean. Don't forget that the MBean register itself in the T= omcat's MBeanServer in its constructor. + Take a look especially at the contextInitialized method. It just instanti= ates our custom MBean. Don't forget that the MBean register itself in the T= omcat's MBeanServer in its constructor. DO NOT FORGET to change the ''packa= ge'' line according to your application architecture. - DO NOT FORGET to change the ''package'' line according to your applicatio= n architecture. = Then, you have to modify your WEB-INF/web.xml file to make Tomcat execute= your ContextListener. + = {{{ = @@ -1074, +1050 @@ }}} In his tutorial, Christopher Blunck suggests to compile the ContextListen= er.java file in a jar archive and then place it into our WEB-INF/lib folder= . In my own experiments, I never found any difference without doing this.<<= BR>> = - 4. The '''''mbeans-descriptor.xml''''' file : The only entry in the Tomca= t documentation about custom MBean is about this file. It says "''You may a= lso add MBean descriptions for custom components in a mbeans-descriptor.xml= file, located in the same package as the class files it describes.''". Unf= ortunately, instead of reading this file, Tomcat applied its own templates = to replace my MBeans attributes and operations descriptions... + 4. The '''''mbeans-descriptor.xml''''' file : The only entry in the Tomca= t documentation about custom MBean is about this file. It says "''You may a= lso add MBean descriptions for custom components in a mbeans-descriptor.xml= file, located in the same package as the class files it describes.''". Unf= ortunately, instead of reading this file, Tomcat applied its own templates = to replace my MBeans attributes and operations descriptions... I really did= n't figure out what is the correct way of using and placing this file. So I= don't use it. - I really didn't figure out what is the correct way of using and placing t= his file. So I don't use it. = - 5. The configuration should be over. You should have done those operation= s : = + 5. The configuration should be over. You should have done those operation= s : - a. Build your MBean,<
> - b. Compile it and place the .jar archive in the Tomcat's /lib folder,<> - c. Build your ContextListener.java,<
> - d. Add a reference to your ContextListener inside your WEB-INF/web.xml f= ile,<
> = + a. Build your MBean,<
> b. Compile it and place the .jar archive in t= he Tomcat's /lib folder,<
> c. Build your ContextListener.java,<
> d.= Add a reference to your ContextListener inside your WEB-INF/web.xml file,<=
> + = - You can try to run your project. Open the [[http://localhost:8080/manager= /jmxproxy]] page and find your custom MBean (with a simple ctrl+f). You can= see its domain, name, type and its attributes and methods.<
>You can no= w use this MBean in your application by getting a reference to the Tomcat's= MBean server : = + You can try to run your project. Open the http://localhost:8080/manager/j= mxproxy page and find your custom MBean (with a simple ctrl+f). You can see= its domain, name, type and its attributes and methods.<
>You can now us= e this MBean in your application by getting a reference to the Tomcat's MBe= an server : + = {{{ - MBeanServer mbs =3D ManagementFactory.getPlatformMBeanServer(); = + MBeanServer mbs =3D ManagementFactory.getPlatformMBeanServer(); //call operations with invoke(...) and attributes with getAttributes(...) }}} Do not hesitate to check the ManagementFactory class javadoc. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org