Search code examples
javagoogle-app-enginerestcode-reuse

Google App Engine Code Reuse Across Projects


I am just starting out learning Java, GAE etc.

I have started a project with the GAE in the Eclipse IDE. I am creating a website AND a RESTful web service using GAE, Jersey, JAXB etc This includes several code files in the src directory of the project which handle the HTTP requests, persist data to the data store etc. I also have several files in the war directory html files, jsp etc which are any web UI I have.

I want to start a second project for a second website but I don't want to have to recreate or copy the existing java code in the new project I want to be able to reuse the codeline from the first project and as I maintain that code it is updated in all projects.

In .net development this is simple because everything compiles up into a set of assemblies (dll files) that I can reuse in many projects. As soon as I make changes and compile up the reused code all the projects referencing those assemblies automatically have the new version.

How can I achieve similar code reuse in GAE development?


Solution

  • Are you using Eclipse? In that case, you could do (on your project) new->folder and then select advanced options, check link to folder in the file system. Link this to your source (sub)folder in another project.

    This way, you can even edit this shared code in both projects, and when you compile one of these projects, the compiled classes will be in your war package (of that particular project).

    Note: I actually took the 'common' code and put it into a seperate project.

    [Edit: subsequently designate this folder as a 'source folder' via project->build path->source]