title: How to shutdown self-hosted Apache CXF web service?
body: <p>I have a console application which can be briefly described with this code:</p>
  
  <pre><code>public static void main(String[] args) throws InterruptedException {
      JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
      sfb.setResourceClasses(DummyService.class);
      sfb.setResourceProvider(DummyService.class, new SingletonResourceProvider(new DummyServiceImpl()));
      sfb.setProvider(new JacksonJaxbJsonProvider());
      sfb.setAddress("http://0.0.0.0:9000/");
      BindingFactoryManager manager = sfb.getBus().getExtension(BindingFactoryManager.class);
      JAXRSBindingFactory bindingFactory = new JAXRSBindingFactory();
      bindingFactory.setBus(sfb.getBus());
      manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, bindingFactory);
      Server server = sfb.create();       
      server.stop(); // here
  }
  </code></pre>
  
  <p>I run this program from Eclipse and I expect it to finish immediately, because I have <code>server.stop()</code> right in the end. This line of code is executed by application remains alive, so I have to shutdown it manually. Here's the log CXF prints to the console:</p>
  
  <pre><code>Aug 13, 2012 10:51:10 PM org.apache.cxf.endpoint.ServerImpl initDestination
  INFO: Setting the server's publish address to be http://0.0.0.0:9000/
  2012-08-13 22:51:10.598:INFO:oejs.Server:jetty-7.5.3.v20111011
  2012-08-13 22:51:10.646:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:9000 STARTING
  2012-08-13 22:51:10.662:INFO:oejsh.ContextHandler:started o.e.j.s.h.ContextHandler{,null}
  2012-08-13 22:51:10.663:INFO:oejsh.ContextHandler:stopped o.e.j.s.h.ContextHandler{,null}
  </code></pre>
  
  <p>After a call to <code>server.stop()</code> application is still running, but server doesn't respond any requests, so it feels like I need to shutdown something else.</p>
  
  <p>What is a proper way to stop it?</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>server.stop();
  server.destroy();
  </code></pre>
  
  <p>Also doesn't work.</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
    &lt;artifactId&gt;cxf-bundle-jaxrs&lt;/artifactId&gt;
    &lt;version&gt;2.6.1&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>