使用maven jetty插件在java 8上运行jetty 9时出现错误扫描文件[重复]
Posted
技术标签:
【中文标题】使用maven jetty插件在java 8上运行jetty 9时出现错误扫描文件[重复]【英文标题】:Getting Error scanning file when running jetty 9 on java 8 using the maven jetty plugin [duplicate] 【发布时间】:2014-05-13 11:17:12 【问题描述】:我正在使用servlet-3.1、jetty-9 在jdk-8 上运行并使用maven-jetty-plugin
运行一个简单的Hello World
Web 应用程序。
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);
并在web.xml
文件中很好地映射:
<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>
但是在运行 mvn jetty:run 时,码头似乎无法找到我的 servlet 类,我在这里缺少什么?
--- 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/,STARTINGfile:/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/,STARTINGfile:/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@506594a5HTTP/1.10.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>
更新:
将maven-compiler-plugin
的配置从1.8 更改为1.7 后工作,将java-8 与jetty-9 一起使用有什么问题?
【问题讨论】:
与您的问题无关,但您忘记在message.getBytes()
中指定要使用的编码
@fge +1 ,这只是一个启动和运行的 Hello World 示例 :)
【参考方案1】:
检查一下
http://vaskoz.wordpress.com/2013/12/18/fix-jetty-9-1-for-jdk8-annotations/
Jetty 9.1.0 与 ASM 4.1 捆绑在一起,但使用字节码级别 1.8 和注释运行会导致以下错误: java.lang.RuntimeException:扫描文件 PingController.class 时出错 在 org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:705)
【讨论】:
【参考方案2】:为了使这项工作,您必须暂时将 ASM 5 添加到 jetty-maven-plugin 的依赖项中
<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>
【讨论】:
这可能根本不起作用,因为 jetty 依赖于具有不同“组”asm 的旧版本,因此 maven 可能无法管理依赖项的交换。 对我不起作用。 jetty-maven-plugin 9.4.0.v20161208以上是关于使用maven jetty插件在java 8上运行jetty 9时出现错误扫描文件[重复]的主要内容,如果未能解决你的问题,请参考以下文章