Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Jetty/Howto/Run Jetty with JConsole

< Jetty‎ | Howto
Revision as of 04:36, 25 August 2009 by Unnamed Poltroon (Talk)



Introduction

JConsole is a graphical tool, which allows you to remotely manage and monitor your server and web application status using JMX.


Steps

Monitoring Jetty with JConsole

To monitor Jetty's server status with JConsole, all you need to do is make sure JConsole is running, and start Jetty with a special system property

Starting up Jetty Standalone

This is straightforward from the command line, when running the standalone Jetty binary.

 java -Dcom.sun.management.jmxremote -jar start.jar [config files]
 jconsole &        # runs jconsole in the background 

Starting up Jetty Maven Plugin

If you are running the Jetty Maven Plugin, you must set the system property com.sun.management.jmxremote on Maven before running the plugin. The way to do this is to set your MAVEN_OPTS environment variable (if you're not sure how to do this, consult the Maven documentation).

Here is an example which sets the system property on the fly in a BASH shell, before starting up Jetty via the plugin:

 export MAVEN_OPTS=-Dcom.sun.management.jmxremote
 mvn jetty:run
 jconsole &        # runs jconsole in the background 

Connecting to your server process

However you start up Jetty, you will see a dialog box from JConsole with a list of running processes you can connect to. It should look something like so:

New connection dialog box in JConsole

Idea.png
Finding your process
If you don't see your Jetty process in the list of processes you can connect to, quickly switch tabs, or else close and reopen a new "New Connection" dialog window. This will force JConsole to refresh the list, and recognize your newly-started Jetty process


Select the start.jar entry and click on the "Connect" button. A new JConsole window will open:

Jconsole2.jpg

From this window you will be able to monitor memory usage, thread usage, classloading and VM statistics. You'll also be able to perform operations such as doing a manual garbage collect. JConsole is an extremely powerful and useful tool.


Managing Jetty Objects with JConsole

The MBean tab of JConsole allows access to managed objects within the Java application, including MBeans provided by the JVM. If you also want to be able to interact with the Jetty JMX implementation via JConsole, then you need to start Jetty JMX in a form that JConsole can access.

Starting up Jetty Standalone

Starting up the Jetty server is still straightforward, but requires two additional arguments, the OPTIONS=default,jmx start option to load the JMX-related JARs, and then the etc/jetty-jmx.xml configuration, to configure the JVM JMX Server.

   java -Dcom.sun.management.jmxremote -jar start.jar OPTIONS=default,jmx etc/jetty-jmx.xml etc/jetty.xml [more config files]
   jconsole &

Starting up Jetty Maven Plugin

The easiest way to do this is to supply the etc/jetty-jmx.xml file in the plugin configuration . Do this like so:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    ...
    <jettyConfig>/path/to/jetty-jmx.xml</jettyConfig>
    ...
  </configuration>
</plugin>
Note.png
Merging with existing configuration files
If you already have a Jetty configuration file that you use with the plugin, you can merge the contents of etc/jetty-jmx.xml into it


Then, just as above, start up JConsole and Jetty:

 export MAVEN_OPTS=-Dcom.sun.management.jmxremote
 mvn jetty:run
 jconsole &        # runs jconsole in the background

Back to the top