domingo, 14 de julho de 2013

Fixing Run-Jetty-Run Eclipse Plugin to Run Websockets



Run-Jetty-Run is an Eclipse plugin for running and debugging web apps using Jetty container. Although it has been a great and useful tool in the past days, lately, when I was playing around with websockets, I’ve found it was not working properly as it should.


It is important to say that the current stable build of Run-Jetty-Run plugin does not support the latest Jetty version (i.e. 9.0.4), so it became necessary to get its nightly build. Once I downloaded it, I've noticed it was not up-to-date either. Actually the last nightly build is pretty old too (the build date is 01/02/2013) and, unfortunately, it only supports Jetty 9.0.0.M3.


So, If you are facing the below issue or if you are a curious person, I would suggest you to keep reading.


java.util.ServiceConfigurationError: org.eclipse.jetty.websocket.servlet.WebSocketServletFactory: Provider org.eclipse.jetty.websocket.server.WebSocketServerFactory not found
at java.util.ServiceLoader.fail(ServiceLoader.java:231)
at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:365)
at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
at org.eclipse.jetty.websocket.servlet.WebSocketServlet.init(WebSocketServlet.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:242)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:516)
at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:398)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:642)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:445)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1054)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:372)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:988)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:410)
at org.eclipse.jetty.server.HttpChannel.run(HttpChannel.java:245)
at org.eclipse.jetty.server.HttpConnection$1.run(HttpConnection.java:75)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:597)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:528)
at java.lang.Thread.run(Thread.java:722)


Once the Run-Jetty-Run team seems to not be working anymore and since there were some changes in the internal Jetty API, I’ve decided to fix it by myself and to post the result to make life simple for everyone trying to run websockets into Eclipse.


It is important to say that this fix was tested only in the Eclipse Kepler. So, in order to avoid other issues, ensure you have the latest version of Kepler IDE. After that, you can follow the following steps:


  1. First of all, you must install the core of the Run-Jetty-Run plugin.
    1. For that, go to Help -> Install New Software.
    2. Then, enter the http://run-jetty-run.googlecode.com/svn/trunk/updatesite-nightly URL and install the Run Jetty Run Feature (Required)
  2. Once the core plugin has being installed, you must install my customized support for running Jetty 9.0.4.
    1. Copy the downloaded jar into the /<YOU_ECLIPSE_KEPLER_HOME>/plugins
    2. And, restart the eclipse
  3. Finally, right click on your websocket app and choose RunAs -> Run Jetty
    1. In Jetty tab, select the following Jetty Version: Jetty 9.0.4.by.Rubbo
    2. In Jetty Classpath tab, add your project in the Custom Jetty Classpath
      1. It is important to say that this step is only necessary because there is another bug in the core plugin which I didn’t want to lose my time to fix.
    3. So, we are done!!
      1. Click in the Run button and have fun..



Hope I’ve helped to make your life simple. ;-)

Thanks for reading.

Nenhum comentário:

Postar um comentário