This might be a very trivial question, but I'm having trouble finding an answer:
Using the Google Plugin for Eclipse, I would like to develop a plain old Java application (not a web-app), that uses AppEngine for cloud storage.
For this, I could, of course, simply create two projects, one containing the AppEngine server and one containing the Java application.
But I'm wondering whether it is possible to set up a single project in Eclipse that contains both the server and the client code (like for a GWT project). To execute it for local debugging, I would then want Eclipse to launch Tomcat to make my servlets available and then launch my Main.java from the client directory of the project as if the project was just a simple Java application. Is this what the "Launch and deploy from this directory" checkbox is for in the "Google" -> "Web Application" settings? If so, how do I use it?
I found one way to do it, but it's a bit cheesy.
First, add the following helper-class to the project:
Then, add the following line to the entry class:
Finally, create the appropriate Run Configuration:
Now, if you launch this Run Configuration, it will first bring up the AppEngine server and then continue with the rest of the
main(...)
method in the entry class. Since the server thread is marked as a daemon thread, once the other code inmain(...)
completes, the application quits normally, shutting down the server as well.Not sure if this is the most elegant solution, but it works. If someone else has a way to achieve this without the
DevServer
helper-class, please do post it!Also, there might be a more elegant way to check whether the AppEngine server is running, other than pinging it with a URL connection as I did above.
Note: The AppEngine Dev Server registers its own
URLStreamHandlerFactory
to automatically mapHttp(s)URLConnections
onto AppEngine's URL-fetch infrastructure. This means that you get errors complaining about missing url-fetch capabilities if you then useHttpURLConnections
in your client code. Luckily, this can be fixed in two way as described here: Getting a reference to Java's default http(s) URLStreamHandler.