java.lang.NoClassDefFoundError:org / eclipse / jetty / server / Handler

时间:2019-05-11 18:50:55

标签: java rest jersey jetty

我正在尝试使用IntelliJ IDE在Java上设置跳船衫。我的代码在IntelliJ中运行良好,但是在运行.jar的maven build时出现以下错误。关于此问题的任何建议将非常有帮助。提前谢谢。

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.Handler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

我的代码看起来像这样。

ServletContextHandler context = new 
ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");

Server server = new Server(2222);
server.setHandler(context);
ServletHolder servlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
servlet.setInitOrder(0);

servlet.setInitParameter("jersey.config.server.provider.classnames", Resource.class.getCanonicalName());

try {
    server.start();
    server.join();
} catch (Exception e) {
    System.out.println(e);
} finally {
    server.destroy();
}

我的pom.xml看起来像这样

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
  </dependency>
<dependency>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-server</artifactId>
  <version>9.4.18.v20190429</version>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-servlet</artifactId>
  <version>9.4.18.v20190429</version>
</dependency>
<dependency>
  <groupId>org.glassfish.jersey.core</groupId>
  <artifactId>jersey-server</artifactId>
  <version>2.7</version>
</dependency>
<dependency>
  <groupId>org.glassfish.jersey.containers</groupId>
  <artifactId>jersey-container-servlet-core</artifactId>
  <version>2.7</version>
</dependency>
<dependency>
  <groupId>org.glassfish.jersey.media</groupId>
  <artifactId>jersey-media-moxy</artifactId>
  <version>2.7</version>
</dependency>
<dependency>
  <groupId>org.glassfish.jersey.ext</groupId>
  <artifactId>jersey-mvc-jsp</artifactId>
  <version>2.21</version>
</dependency>
</dependencies>

我正在使用cmd mvn package创建jar文件。

0 个答案:

没有答案