I’ve just started learning Spring (and Java) and I’m putting together an application that has several parts to it. What I’d like is some opinions on how to structure the application in terms of within an IDE, and when deploying. I use intellij 11 with Tomcat 7 for reference.
My application consists of these pieces:
- Main public website (www.myapp.com)
- REST service (www.myapp.com/rest)
- Admin website (admin.myapp.com)
- UI resources (cdn.myapp.com)
I need to share Java classes between all of these apps (my service layer), and also there’s the issue of sharing UI resources (css, js, images) between the main website and the admin site.
How should I best go about organising these in my IDE and on Tomcat?
My thoughts so far are that each of the apps mentioned would be separate WAR files (they don’t need to share sessions). I would create my service layer as a JAR which could be used by any of the apps. How would you represent this in intellij or Eclipse?
I guess that my UI resources on cdn.myapp.com can just be included as they normally would and again these UI resources would just be packaged as another WAR. Does this sound ok?
How do you organise your projects with multiple sub-apps like this?
As you can see I’m not necessarily after a hard and fast rule, just opinions really (though if anyone has a solid clear cut answer then great).
Thanks,
James.
I would look into using a build tool like maven, Gradle or Buildr. They all use a standard directory structure and supports sub-modules.
Using sub-modules you can for example create two “war modules”, and put the shared resources in a shared jar.
When it comes to tomcat you can deploy the different war files in separate contexts, or use a reverse-proxy to create the url scheme of choice.
IntelliJ has first class support for maven (not sure about buildr and gradle), so you just point the IDE to the root-pom.xml, and it automatically creates the correct configuration for you.
Have a look at github, for instance cucumber-jvm for examples of how to configure parent/sub modules in a given build tool.