Skip to content

Instantly share code, notes, and snippets.

@linux-china
Created March 28, 2013 01:33
Show Gist options
  • Save linux-china/5259757 to your computer and use it in GitHub Desktop.
Save linux-china/5259757 to your computer and use it in GitHub Desktop.
Nailgun servlet to start Nailgun server.
import com.martiansoftware.nailgun.NGServer;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
/**
* nailgun servlet
*
* @author linux_china
*/
public class NailgunServlet extends HttpServlet {
/**
* start Nailgun Server
*
* @param config servlet config
* @throws ServletException servlet exception
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
new Thread(new Runnable() {
@Override
public void run() {
try {
NGServer ngServer = new NGServer();
ngServer.run();
System.out.println("Nailgun started with listen port 2113.");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}
@linux-china
Copy link
Author

Maven dependency

   <dependency>
        <groupId>com.martiansoftware</groupId>
        <artifactId>nailgun-server</artifactId>
        <version>0.9.1</version>
   </dependency>

web.xml modify

   <servlet>
       <servlet-name>NailGunServlet</servlet-name>
       <servlet-class>org.mvnsearch.shop.web.portal.servlet.NailgunServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
   </servlet>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment