小编DaS*_*010的帖子

检测运行的servlet容器是否为Eclipse Jetty

我尝试检测应用程序是否在Eclipse Jetty上作为servlet容器运行.我找到了Mortbay Jetty解决方案,但不是Eclipse的实际版本.我修改了现有的检查并将Classpath从"/org/mortbay/jetty/Server.class"替换为"/org/eclipse/jetty/server/Server.class",但是在Jetty 9上检查失败.运行相同的应用程序tomcat很成功.我错了什么?

代码如下:

private boolean detect(final String clazz) {
  try {
    final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    systemClassLoader.loadClass(clazz);
    return true;
  } catch (final ClassNotFoundException cnfe) {
    final Class<?> classObj = getClass();
      if (classObj.getResource(clazz) != null) {
        return true;
  } else {
        return false;
      }
  }
}
Run Code Online (Sandbox Code Playgroud)

调用函数:

detect("/org/eclipse/jetty/server/Server.class");
Run Code Online (Sandbox Code Playgroud)

eclipse jetty detection

5
推荐指数
1
解决办法
1795
查看次数

标签 统计

detection ×1

eclipse ×1

jetty ×1