perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.65k stars 1.56k forks source link

Jetty embedded server class not found exception with spark 2.6.0 #933

Open OctavioGalland opened 7 years ago

OctavioGalland commented 7 years ago

Hi, I tried using spark in a maven project with eclipse and got the following error when running the app: (using lubuntu 17.04 with eclipse oxygen and openjdk8)

Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler
    at spark.embeddedserver.EmbeddedServers.initialize(EmbeddedServers.java:40)
    at spark.Service.lambda$init$2(Service.java:491)
    at java.lang.Thread.run(Thread.java:748)
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:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 3 more

This does not happen if I use spark 2.5 or if I manually add the eclipse Jetty dependency. My pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>TestGroup</groupId>
  <artifactId>TestArtifact</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>com.sparkjava</groupId>
      <artifactId>spark-core</artifactId>
      <version>2.6.0</version>
    </dependency>
       <!-- Jetty dependency, without this the app crashes
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-server</artifactId>
      <version>9.4.7.v20170914</version>
    </dependency>
        -->
  </dependencies>
</project>

The main class is just the example copied frm the sparkjava website.

Tell me if I can provide more info!

Tito5e commented 3 years ago

I can't use English so I'm using google translate

I'm sorry to answer the question a long time ago

Probably, you need to include org.eclipse.jetty in maven-shade-plugin