Getting Error scanning file when running jetty 9 on java 8 using the maven jetty plugin [duplicate]
Asked Answered
B

2

10

I'm running a trivial Hello World web application using , running on and using the maven-jetty-plugin.

public class HelloWorldServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)  {
        try {
            String message = "Hello Jetty From the HelloWorldServlet";
            OutputStream stream = response.getOutputStream();
            stream.write(message.getBytes());
            stream.flush();
        } catch (IOException ex) {
            Logger.getLogger(HelloWorldServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

And well mapped in the web.xml file:

<servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>org.tarrsalah.jetty.example.HelloWorldServlet</servlet-class>                
    </servlet>

    <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

But it seems that jetty can't fin my servlet class when running mvn jetty:run , what am I missing here ?

--- jetty-maven-plugin:9.1.3.v20140225:run (default-cli) @ jetty-example ---
2014-04-02 10:09:46.126:INFO::main: Logging initialized @12796ms
Configuring Jetty for project: jetty-example
webAppSourceDirectory not set. Trying src/main/webapp
Reload Mechanic: automatic
Classes = /home/tarrsalah/src/misc/jetty-exampe/target/classes
Context path = /
Tmp directory = /home/tarrsalah/src/misc/jetty-exampe/target/tmp
Web defaults = org/eclipse/jetty/webapp/webdefault.xml
Web overrides =  none
web.xml file = file:/home/tarrsalah/src/misc/jetty-exampe/src/main/webapp/WEB-INF/web.xml
Webapp directory = /home/tarrsalah/src/misc/jetty-exampe/src/main/webapp
2014-04-02 10:09:46.291:INFO:oejs.Server:main: jetty-9.1.3.v20140225
2014-04-02 10:09:46.954:INFO:oeja.AnnotationConfiguration:main: Scanned 1 container path jars, 0 WEB-INF/lib jars, 1 WEB-INF/classes dirs in 82ms for context o.e.j.m.p.JettyWebAppContext@1f38957{/,file:/home/tarrsalah/src/misc/jetty-exampe/src/main/webapp/,STARTING}{file:/home/tarrsalah/src/misc/jetty-exampe/src/main/webapp/}
2014-04-02 10:09:46.954:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.m.p.JettyWebAppContext@1f38957{/,file:/home/tarrsalah/src/misc/jetty-exampe/src/main/webapp/,STARTING}{file:/home/tarrsalah/src/misc/jetty-exampe/src/main/webapp/}
java.lang.RuntimeException: Error scanning file HelloWorldServlet.class
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:705)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:821)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:159)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:542)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:744)
Caused by: 
java.lang.IllegalArgumentException
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:970)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:700)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:821)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:159)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:542)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:744)
2014-04-02 10:09:46.958:WARN:oejsh.RequestLogHandler:main: !RequestLog
2014-04-02 10:09:47.108:INFO:oejs.ServerConnector:main: Started ServerConnector@506594a5{HTTP/1.1}{0.0.0.0:8080}
2014-04-02 10:09:47.109:INFO:oejs.Server:main: Started @13779ms
Started Jetty Server

pom.xml

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.1.3.v20140225</version>              
</plugin>

Update:

Worked after changing the configuration of maven-compiler-plugin from 1.8 to 1.7, What'is wrong with using with ?

Bicuspid answered 2/4, 2014 at 9:23 Comment(2)
Unrelated to your problem but you forget to specify the encoding to use in message.getBytes()Keating
@Keating +1 , It's just a Hello World example to get things up and running :)Bicuspid
L
12

To make this work, you have to add ASM 5 to the dependencies of the jetty-maven-plugin for the time being

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>5.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm-commons</artifactId>
            <version>5.0.2</version>
        </dependency>
    </dependencies>
</plugin>
Locoweed answered 2/5, 2014 at 11:37 Comment(3)
This may not at all work because jetty is dependent on the older version which has a different "group" asm and thus maven will probably not manage the swap of the dependencies.Ignition
does not work for me. jetty-maven-plugin 9.4.0.v20161208Millimeter
how do we find the plugin source directory?Confound
S
3

check this

http://vaskoz.wordpress.com/2013/12/18/fix-jetty-9-1-for-jdk8-annotations/

Jetty 9.1.0 comes bundled with ASM 4.1 but running with bytecode level 1.8 and annotations causes the following error: java.lang.RuntimeException: Error scanning file PingController.class at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:705)

Saskatoon answered 19/8, 2014 at 5:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.