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.
Jetty/Howto/Run Jetty with JConsole
Contents
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 OPTIONS=jmx,default etc/jetty-jmx.xml etc/jetty.xml 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:
Select the start.jar entry and click on the "Connect" button. A new JConsole window will open:
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>
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