2014-04-02 14 views
6

Tôi đang chạy ứng dụng web tầm thường Hello World sử dụng , chạy trên và sử dụng maven-jetty-plugin.Bắt lỗi khi quét tệp khi chạy cầu tàu 9 trên java 8 bằng cách sử dụng plugin cầu cảng maven

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); 
     } 
    } 

Và cũng ánh xạ trong 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> 

Nhưng có vẻ như cầu cảng không thể vây lớp servlet của tôi khi chạy cầu cảng mvn: chạy, những gì tôi thiếu ở đây?

--- 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 [email protected]{/,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 [email protected]{/,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 [email protected]{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> 

Cập nhật:

Làm việc sau khi thay đổi cấu hình của maven-compiler-plugin 1,8-1,7, What'is sai với việc sử dụng với ?

+4

Không liên quan đến vấn đề của bạn, nhưng bạn quên để xác định mã hóa để sử dụng trong 'nhắn.getBytes() ' – fge

+0

@fge +1, Nó chỉ là một ví dụ Hello World để có được mọi thứ và chạy :) – tarrsalah

Trả lời

-2

Do sự khác biệt giữa phiên bản Java (8) và các phiên bản của ASM gói trong Jetty, bạn có loại ngoại lệ bạn đã có kinh nghiệm.

Bạn cần phải thực hiện các phiên bảntương thích với nhau bằng tảiASM5,0 hoặc lớn hơn và thay thế sau 2 file trong cài đặt Jetty thư mục:

1.asm-4.1.jarvớiasm-5.0_BETA.jar

2.asm-commons-4.1.jarvớiasm-commons-5.0_BETA.jar

+1

Điều này sẽ được thay đổi trong các bản phát hành trong tương lai của Jetty 9.1? –

+1

Đã có bản cập nhật cho thư viện asm mà chúng tôi sử dụng, cùng với một số thay đổi api để hỗ trợ quét bytecode JDK8 mới. – GingerHead

7

Để thực hiện việc này, bạn cần phải thêm ASM 5 đến sự phụ thuộc của ghềnh đá-maven- plugin cho trong thời gian tới

<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> 
+1

Điều này có thể không hoạt động vì cầu tàu phụ thuộc vào phiên bản cũ hơn có một nhóm "asm" khác nhau và do đó maven có thể sẽ không quản lý việc trao đổi các phụ thuộc. – adam

+1

không hoạt động đối với tôi. jetty-maven-plugin 9.4.0.v20161208 – Eugene

Các vấn đề liên quan