Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty 9 Server has no start() method

I am trying to embed a Jetty server in an application and am seeing a really strange problem:

According to documentation, a simple server (which I am building as a test) can be started up using the following code:

import org.eclipse.jetty.server.Server;

public class SimpleServer throws Exception
{

   public static void main(String[] args)
   {
      Server server = new Server(8080);

      server.start();
      server.join();
   }

}

I believe I have the correct Jar file from the downloaded Jetty:

jetty-server-9.3.7.v20160115.jar

Unfortunately, I am seeing that the Server class I am using has no public start() method. It has a protected start() method that has a LifeCycle parameter, but that is it. The public start() method referenced in the documentation (and in several answers here in Stack Overflow) does not exist!

Am I using the right Server class? If not, where do I get a proper one???

Someone please advise...

like image 923
Factor Three Avatar asked Mar 01 '16 22:03

Factor Three


2 Answers

You need also add "jetty-util-{version}" into your project and this will fix your issue. Or you can use maven in your project and add "jetty-server-{version}" as maven dependency. Maven will automatically download all jetty-server relative jars (including jetty-util-{version}).

like image 163
rholovakha Avatar answered Nov 20 '22 01:11

rholovakha


There's no problem here.

A public modifier Server.start() exists, and has existed since (at least) Jetty 5.0 days.

Not sure what library / build you are using, but this method is not protected, in the Server class, the AbstractLifeCycle (abstract) class or even the LifeCycle interface.

like image 1
Joakim Erdfelt Avatar answered Nov 20 '22 01:11

Joakim Erdfelt