this might trivial question, i'm having trouble finding answer:
using google plugin eclipse, develop plain old java application (not web-app), uses appengine cloud storage.
for this, could, of course, create 2 projects, 1 containing appengine server , 1 containing java application.
but i'm wondering whether possible set single project in eclipse contains both server , client code (like gwt project). execute local debugging, want eclipse launch tomcat make servlets available , launch main.java client directory of project if project simple java application. "launch , deploy directory" checkbox in "google" -> "web application" settings? if so, how use it?
i found 1 way it, it's bit cheesy.
first, add following helper-class project:
// other imports import com.google.appengine.tools.development.devappservermain; public class devserver { public static void launch(final string[] args) { logger logger = logger.getlogger(""); logger.info("launching appengine server..."); thread server = new thread() { @override public void run() { try { devappservermain.main(args); // run devappserver } catch (exception e) { e.printstacktrace(); } } }; server.setdaemon(true); // shut down server when rest of app completes server.start(); // run server in separate thread urlconnection cxn; try { cxn = new url("http://localhost:8888").openconnection(); } catch (ioexception e) { return; } // should never happen boolean running = false; while (!running) { // maybe add timeout in case server fails load try { cxn.connect(); // try connect server running = true; // maybe limit rate thread.sleep(...) here } catch (exception e) {} } logger.info("server running."); } } then, add following line entry class:
public static void main(string[] args) { devserver.launch(args); // launch appengine dev server (blocks until ready) // else } finally, create appropriate run configuration:
- simply click "run as" -> "web application". create default run configuration.
- in created run configuration, under "main"-tab select own entry class "main class" instead of default "com.google.appengine.tools.development.devappservermain".
now, if launch run configuration, first bring appengine server , continue rest of main(...) method in entry class. since server thread marked daemon thread, once other code in main(...) completes, application quits normally, shutting down server well.
not sure if elegant solution, works. if else has way achieve without devserver helper-class, please post it!
also, there might more elegant way check whether appengine server running, other pinging url connection did above.
note: appengine dev server registers own urlstreamhandlerfactory automatically map http(s)urlconnections onto appengine's url-fetch infrastructure. means errors complaining missing url-fetch capabilities if use httpurlconnections in client code. luckily, can fixed in 2 way described here: getting reference java's default http(s) urlstreamhandler.
Comments
Post a Comment