我正在尝试使用com.j256.simplejmx实现简单的JMX客户端/服务器.我想使用Web浏览器监视我的对象.我复制了一段非常简单的代码:
package com.my.package.jmx;
import com.j256.simplejmx.web.JmxWebServer;
public class JMXServer {
public static void main(String[] args) throws Exception {
JmxWebServer jmxWebServer = new JmxWebServer(8123);
jmxWebServer.start();
}
}
当我运行它时,我有一个例外:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/util/thread/ThreadPool
at com.my.package.jmx.JMXServer.main(JMXServer.java:9)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.util.thread.ThreadPool
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
我将此添加到我的pom.xml中:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.1.3.v20140225</version>
</dependency>
我再次运行它,然后又得到另一个惊喜:
防爆
ception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/AbstractConnector
at com.my.package.jmx.JMXServer.main(JMXServer.java:9)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.AbstractConnector
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
因此,再次更新我的pom.xml:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.1.3.v20140225</version>
</dependency>
它再次给我一个错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/nio/SelectChannelConnector
at com.mu.package.jmx.JMXServer.main(JMXServer.java:9)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.nio.SelectChannelConnector
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
我找不到任何解决方案.我还应该添加什么到pom.xml文件中?也许依赖版本存在问题?
先感谢您.
我编辑了pom.xml
<project...>
<properties>
<jetty-version>8.1.9.v20130131</jetty-version>
</properties>
<dependencies>
<dependency>
<groupId>com.j256.simplejmx</groupId>
<artifactId>simplejmx</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty-version}</version>
<optional>true</optional>
</dependency>
</dependencies>
</project>
现在,我可以运行此服务器:
INFO Server - jetty-8.1.9.v20130131
INFO AbstractConnector - Started SelectChannelConnector@0.0.0.0:8123
但是当我进入Web浏览器并输入以下内容时:
localhost:8123
它引发异常:
WARN nio -
java.lang.SecurityException: class "javax.servlet.AsyncContext"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(Unknown Source)
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jetty.server.AbstractHttpConnection.<init>(AbstractHttpConnection.java:157)
at org.eclipse.jetty.server.AsyncHttpConnection.<init>(AsyncHttpConnection.java:50)
at org.eclipse.jetty.server.nio.SelectChannelConnector.newConnection(SelectChannelConnector.java:285)
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newConnection(SelectChannelConnector.java:325)
at org.eclipse.jetty.server.nio.SelectChannelConnector.newEndPoint(SelectChannelConnector.java:272)
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newEndPoint(SelectChannelConnector.java:331)
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.createEndPoint(SelectorManager.java:841)
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.doSelect(SelectorManager.java:496)
at org.eclipse.jetty.io.nio.SelectorManager$1.run(SelectorManager.java:290)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)
解决方法:
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.nio.SelectChannelConnector
因此,现在SimpleJMX具有8.1.9.v20130131 Jetty的可选依赖项,以支持publishing JMX over web/HTTP.如果您查看pom.xml,您将看到:
<jetty-version>8.1.9.v20130131</jetty-version>
...
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty-version}</version>
<optional>true</optional>
</dependency>
您可以尝试这个版本的Jetty吗?我不确定我是否可以同时支持8.X.X和9.X.X,但我会对其进行研究.