From: Eelco H. <eel...@gm...> - 2006-12-05 07:51:01
|
Hi Erik, I'm afraid JettyLauncher is getting real rusty. Geoff stopped using his brain child like two years ago, I took it over for a while, but rarely use it myself nowadays, and I'm quite out-of-time to work on it. Brian, I'm not sure whether you're still supporting this project, but it has been awfully quiet for the last few months. So Erik... interested in getting yourself an OSS project? ;) Anyway, I can post some Jetty 6 launching code that I'm using here, maybe that'll get you started. First the simplest one: public static void main(String[] args) { Server server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(8080); server.setConnectors(new Connector[] { connector }); WebAppContext web = new WebAppContext(); web.setContextPath("/wicket-examples"); web.setWar("src/main/webapp"); server.addHandler(web); try { server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); System.exit(100); } } Something with more options, including an optional request logger: public void setupServer() throws Exception { server = new Server(); String threadPoolName = System.getProperty("jetty.threadpool.name", "Jetty thread"); int maxIdleTimeMs = Integer.getInteger( "jetty.threadpool.maxIdleTimeMs", 60000); int maxThreads = Integer.getInteger("jetty.threadpool.maxThreads", 255); int minThreads = Integer.getInteger("jetty.threadpool.minThreads", 1); int lowThreads = Integer.getInteger("jetty.threadpool.maxIdleTimeMs", 25); BoundedThreadPool threadPool = new BoundedThreadPool(); threadPool.setName(threadPoolName); threadPool.setMaxIdleTimeMs(maxIdleTimeMs); threadPool.setMaxThreads(maxThreads); threadPool.setMinThreads(minThreads); threadPool.setLowThreads(lowThreads); server.setThreadPool(threadPool); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(Integer.parseInt(tspPort)); server.addConnector(connector); server.setStopAtShutdown(true); // handle static resources ContextHandler html = new ContextHandler(); html.setContextPath(tspHtmlContext); ResourceHandler resHandler = new ResourceHandler(); resHandler.setResourceBase(tspHtmlDir); html.setHandler(resHandler); server.addHandler(html); // The web app WebAppContext tsp = new WebAppContext(); tsp.getSessionHandler().setSessionManager(new Ts4SessionManager()); tsp.setContextPath(tspWarContext); tsp.setWar(tspWarDir); String requestLogFileName = System .getProperty("jetty.ncsa.requestLog.filename"); if (requestLogFileName != null) { StatisticsHandler statisticsHandler = new StatisticsHandler(); statisticsHandler.setServer(server); statisticsHandler.addHandler(tsp); RequestLogHandler requestLogHandler = new RequestLogHandler(); NCSARequestLog requestLog = new NCSARequestLog(); requestLog.setFilename(requestLogFileName); requestLog.setAppend(Boolean .getBoolean("jetty.ncsa.requestLog.append")); requestLog.setRetainDays(Integer.getInteger( "jetty.ncsa.requestLog.retainDays", 90)); requestLog.setExtended(Boolean .getBoolean("jetty.ncsa.requestLog.extended")); requestLogHandler.setRequestLog(requestLog); requestLogHandler.addHandler(tsp); server.addHandler(requestLogHandler); log.info("logging requests to " + requestLogFileName); } else { server.addHandler(tsp); } MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer); server.getContainer().addEventListener(mBeanContainer); mBeanContainer.start(); } public void start() throws Exception { if (server == null) { throw new IllegalStateException("call setupServer first"); } try { server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); server.stop(); System.exit(100); } } The main method basically reads some vars from the command line, set's them on the instance of itself it creates and starts up the server like this: RunAppServer runner = new RunAppServer(); runner.tspWarDir = tspWarDir; runner.tspHtmlDir = tspHtmlDir; runner.tspPort = tspPort; runner.tspHtmlContext = tspHtmlContext; runner.tspWarContext = tspWarContext; runner.setupServer(); runner.start(); Note that you also need jetty-jmx for that. Btw, we're using that for a production system, and so far that works great. Who needs those heavy duty app servers anyway ;) Now, regarding JettyLauncher... If I wanted to get back to develop on that, i would probably get rid of the whole idea of a super-flexible launcher that needs an installed instance of Jetty, but rather package Jetty 6 with the plugin, and make the plugin super-simple to maintain *and* use. Basically a specialized runner like we have now, but then using the included Jetty libs and some basic parameter options like the port to use and a list of web apps (pairs of workspace relative paths to web app dirs and context names, e.g. "wicket-examples/src/main/webapp", "/wicket-examples" but then in a neat GUI of course). If you plan on working on fixing JL and you know you won't support older versions, this is an idea you might consider. Cheers, Eelco On 12/4/06, Erik Gillespie <eri...@gm...> wrote: > First let me apologize for the length email but I hope it has some juicy > details that may help get JettyLauncher working with Jetty6. I pulled down > the source for the JettyLauncher plugin and tried to build it against Jetty6 > and learned some things that may help get the launcher working with newer > versions of Jetty. I'll continue trying to get it to work but someone with > more familiarity with the code might be able to do it faster so I thought > I'd share what I've found so far: > > First, in Jetty6 there's no javax.servlet.jar and there's no > org.mortbay.jetty.jar. Here are the details: > > 1. javax.servlet.jar was renamed to servlet-api-2.5-6.0.2.jar (for Jetty > 6.0.2, I imagine in Jetty 6.0.0 the JAR was called > servlet-api-2.5-6.0.0.jar). > 2. org.mortbay.jetty.jar was split up into two jars: jetty-6.0.2.jar and > jetty-util-6.0.2.jar. Why versions were slapped directly onto the filename > is totally beyond me but I guess that's what we've got to live with. > > Second, I tried creating a javax.servlet.jar and org.mortbay.jetty.jar to > see if I could hack the JettyLauncher into working with Jetty6 but fortunate > did not smile upon me. It seems that the package org.mortbay.http was taken > out and this caused JettyLauncher's references to NCSARequestLog and > SocketListener to break. More details: > > 1. org.mortbay.http.NCSARequestLog is now > org.mortbay.jetty.NCSARequestLog > 2. SocketListener was replaced with > org.mortbay.jetty.bio.SocketConnector > > Third, there seems to have been some other renaming and refactoring that > went on in Jetty6. Namely: > > 1. org.mortbay.jetty.servlet.WebApplicationContext is now > org.mortbay.jetty.webapp.WebAppContext > 2. Server.addWebApplication() no longer exists. It looks like > WebAppContext ctx = new WebAppContext(server, contextPath, > webappContextRoot) may do the trick. > 3. The constructor Server(URL) no longer exists. I stumbled upon > XmlConfiguration and it looks like you create an instance of > XmlConfiguration(URL) and then call xmlConfiguration.configure(server). > 4. The method Server.setRequestLog() no longer exists. It looks like you > create a new RequestLogHandler(), then call handler.setRequestLog(new > NCSARequestLog()), and then call server.addHandler (handler). > > I applied all of my recommended changes (all to PluginRunner.java) and all > of the compiler errors went away so now I can build the JettyLauncher plugin > against Jetty6 (although now the plugin won't work with earlier versions of > Jetty). I get about 54 warnings but it's getting late so I thought I'd pass > along what I have so maybe someone else could help me work through this. > I've attached my version of PluginRunner.java. You'll also need to update > your classpath so that the Jetty6 JAR files (replacements for > javax.servlet.jar and org.mortbay.jetty.jar described above) are found > before you can build the plugin. > > I'll try to keep cranking away on this as I find time, please let me know if > you beat me to it! > > Erik > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > _______________________________________________ > Jettylauncher-plugin mailing list > Jet...@li... > https://lists.sourceforge.net/lists/listinfo/jettylauncher-plugin > > > > |