jetty 9 + JDK 8 + spring 4 Annotations
Asked Answered
J

2

9

After upgrading to JDK 8 , the jetty 9 is no longer able to scan the spring annotations : I get the following error :

MultiException[java.lang.RuntimeException: Error scanning file ApplicationInitializer.class, java.lang.RuntimeException: Error scanning file HibernateConfig.class, java.lang.RuntimeException: Error scanning file MailConfig.class, java.lang.RuntimeException: Error scanning file ServicesConfig.class, java.lang.RuntimeException: Error scanning file WebAppConfig.class]
at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations(AnnotationConfiguration.java:530)
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:441)
at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:466)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:745)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:282)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:154)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)

It was working fine when i used jdk 7 .

The annotations it tries to scan are spring framework 4 annotations something like :

@Configuration
@EnableWebMvc
@ComponentScan("com.cityrentals.rentahouse")
@Import({ HibernateConfig.class, ServicesConfig.class, MailConfig.class })
public class WebAppConfig extends WebMvcConfigurerAdapter {

The error occurs irrespective of if the javaassist dependency is present or not

 <dependency>
   <groupId>org.javassist</groupId>
   <artifactId>javassist</artifactId>
   <version>3.18.1-GA</version>
  </dependency>

Any help is much appreciated

Thanks Suresh

Johnsonian answered 1/4, 2014 at 13:14 Comment(0)
M
9

Because of the version differences between spring mvc Java (8) and the version of ASM bundled in Jetty, you have the kind of exceptions you have experienced.

You need to make the versions compatible with each other by downloading ASM 5.xx and replacing the following 2 files within the Jetty installation folder:

  1. asm-4.x.jar with asm-5.xx.jar

  2. asm-commons-4.x.jar with asm-commons-5.xx.jar

Matildamatilde answered 2/4, 2014 at 10:16 Comment(1)
issue seems to be fixed in jetty-9.2.2 (maybe earlier)Transom
N
3

Using jetty-9.1.x, Java 8 and Spring 4 the answer by Ginger Head is correct. Just to supplement that answer:

If you are using the jetty-runner with version 9.1.x you may notice that it uses a bundled version of asm (bundled in the jar). To get it working with the bundled version I had to add the asm-jars on the classpath, before the jetty-runner-jar and then start jetty-runner without the -jar flag and instead point out the main class (org.eclipse.jetty.runner.Runner).

So, this IS working:

java -cp lib/asm-5.x.jar:lib/asm-commons-5.x.jar:lib/asm-tree-5.x.jar:lib/jetty-runner.jar org.eclipse.jetty.runner.Runner foo.war

The following is NOT working:

java -cp -jar lib/jetty-runner.jar foo.war
or
java -cp lib/asm-5.x.jar:lib/asm-commons-5.x.jar:lib/asm-tree-5.x.jar -jar lib/jetty-runner.jar foo.war
Noncompliance answered 9/5, 2014 at 6:22 Comment(1)
Quick update, this issue has now been resolved in later versions of Jetty (or more specifically in version 9.2.0.v20140526). The new version requires no special handling of the asm-jars for Java 8, Jetty 9 and Spring 4 - it should work out-of-the-box.Noncompliance

© 2022 - 2024 — McMap. All rights reserved.