<property name="cometd.war" value="${tomcat.extras}/cometd.war"/>
<property name="tomcat-bayeux-samples.jar" value="${tomcat.extras}/tomcat-bayeux-samples.jar"/>
+ <property name="catalina-jmx-remote.jar" value="${tomcat.extras}/catalina-jmx-remote.jar"/>
<!-- Classpath -->
<path id="tomcat.classpath">
</echo>
</target>
- <target name="extras" depends="prepare,commons-logging,webservices,bayeux">
+ <target name="jmx-remote" >
+ <!-- Create the JAR file -->
+ <jar jarfile="${catalina-jmx-remote.jar}">
+ <fileset dir="${tomcat.classes}">
+ <include name="org/apache/catalina/mbeans/JmxRemote*" />
+ </fileset>
+ </jar>
+
+ <checksum file="${catalina-jmx-remote.jar}"
+ forceOverwrite="yes" fileext=".md5" />
+
+ </target>
+
+ <target name="extras" depends="prepare,commons-logging,webservices,bayeux,jmx-remote">
</target>
<!-- Download and dependency building -->
protected String accessFile = null;
protected boolean useLocalPorts = false;
+ protected JMXConnectorServer csPlatform = null;
+ protected JMXConnectorServer csCatalina = null;
+
/**
* Get the port on which the Platform RMI server is exported. This is the
* port that is normally chosen by the RMI stack.
// Create the Platform server
- createServer(rmiRegistryPortPlatform, rmiServerPortPlatform, env,
+ csPlatform = createServer("Platform", rmiRegistryPortPlatform,
+ rmiServerPortPlatform, env,
ManagementFactory.getPlatformMBeanServer());
// Create the catalina server
- createServer(rmiRegistryPortCatalina, rmiServerPortCatalina, env,
+ csCatalina = createServer("Catalina", rmiRegistryPortCatalina,
+ rmiServerPortCatalina, env,
MBeanUtils.createServer());
+ } else if (Lifecycle.STOP_EVENT == event.getType()) {
+ destroyServer("Platform", csPlatform);
+ destroyServer("Catalina", csCatalina);
}
}
- private void createServer(int theRmiRegistryPort, int theRmiServerPort,
+ private JMXConnectorServer createServer(String serverName,
+ int theRmiRegistryPort, int theRmiServerPort,
HashMap<String,Object> theEnv, MBeanServer theMBeanServer) {
// Create the RMI registry
} catch (RemoteException e) {
log.error(sm.getString(
"jmxRemoteLifecycleListener.createRegistryFailed",
- Integer.toString(theRmiRegistryPort)), e);
- return;
+ serverName, Integer.toString(theRmiRegistryPort)), e);
+ return null;
}
// Build the connection string with fixed ports
} catch (MalformedURLException e) {
log.error(sm.getString(
"jmxRemoteLifecycleListener.invalidURL",
- url.toString()), e);
- return;
+ serverName, url.toString()), e);
+ return null;
}
// Start the JMX server with the connection string
- JMXConnectorServer cs;
+ JMXConnectorServer cs = null;
try {
cs = JMXConnectorServerFactory.newJMXConnectorServer(
serviceUrl, theEnv, theMBeanServer);
cs.start();
log.info(sm.getString("jmxRemoteLifecycleListener.start",
Integer.valueOf(theRmiRegistryPort),
- Integer.valueOf(theRmiServerPort)));
+ Integer.valueOf(theRmiServerPort), serverName));
} catch (IOException e) {
- log.error(sm.getString(""), e);
+ log.error(sm.getString(
+ "jmxRemoteLifecycleListener.createServerFailed",
+ serverName), e);
+ }
+ return cs;
+ }
+
+ private void destroyServer(String serverName,
+ JMXConnectorServer theConnectorServer) {
+ if (theConnectorServer != null) {
+ try {
+ theConnectorServer.stop();
+ } catch (IOException e) {
+ log.error(sm.getString(
+ "jmxRemoteLifecycleListener.destroyServerFailed",
+ serverName),e);
+ }
}
}
# See the License for the specific language governing permissions and
# limitations under the License.
-jmxRemoteLifecycleListener.createRegistryFailed=Unable to create the RMI registry using port "{0}"
-jmxRemoteLifecycleListener.invalidURL=The JMX Service URL requested, "{0}", was invalid
-jmxRemoteLifecycleListener.serverFailed=The JMX connector server could not be created or failed to start
-jmxRemoteLifecycleListener.start=The JMX Remote Listener has configured the registry on port {0} and the server on port {1}
\ No newline at end of file
+jmxRemoteLifecycleListener.createRegistryFailed=Unable to create the RMI registry for the {0} server using port {1}
+jmxRemoteLifecycleListener.createServerFailed=The JMX connector server could not be created or failed to start for the {0} server
+jmxRemoteLifecycleListener.destroyServerFailed=The JMX connector server could not be stopped for the {0} server
+jmxRemoteLifecycleListener.invalidURL=The JMX Service URL requested for the {0} server, "{1}", was invalid
+jmxRemoteLifecycleListener.start=The JMX Remote Listener has configured the registry on port {0} and the server on port {1} for the {2} server
<h3>JMX Remote Lifecycle Listener
(org.apache.catalina.mbeans.JmxRemoteLifecycleListener)</h3>
+ <p>This listener requires <code>catalina-jmx-remote.jar</code> to be placed
+ in <code>$CATALINA_HOME/lib</code>. This jar may be found in the extras
+ directory of the binary download area.</p>
+
<p>The <strong>JMX Remote Lifecycle Listener</strong> fixes the port used by
the JMX/RMI Server making things much simpler if you need to connect
jconsole or a similar tool to a remote Tomcat instance that is running
<p>If this listener was configured in server.xml as:
<source>
<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"
- rmiRegistryPort="10001" rmiServerPort="10002" />
+ rmiRegistryPortPlatform="10001" rmiServerPortPlatform="10002"
+ rmiRegistryPortCatalina="10003" rmiServerPortCatalina="10004" />
</source>
with the following system properties set (eg in setenv.sh):
<source>