We are developing a Web application consisting of two Eclipse projects. One project is an HTTP-based RESTful Web service; the other project is a Web site. Both will be deployed as WARs. Initially, both will be deployed under the same application server instance, but eventually they'll be on separate boxes.
The Web site app consumes the RESTful WS app. Obviously, there will be code--specifically, domain classes--that are common to both projects. For instance, there might be a resource located at <app>/users which exposes CRUD operations on User objects; to update a user, the Web site app would POST an XML-marshalled User object to <app>/users. Doing a GET to <app>/users/1 would return an XML-marshalled User object.
Obviously, having a User class in both projects would be pretty stupid for a variety of reasons. So I'm wondering what is the best way to go about this? Putting the common code in a JAR that's shared between the two projects is what I have done in the past, but is there a better or easier way?
Edit: Removed RESTful references. Semantics aside, what is the right way to share common code between two Eclipse projects?
Application domains provide an isolation boundary for security, reliability, and versioning, and for unloading assemblies. Application domains are typically created by runtime hosts, which are responsible for bootstrapping the common language runtime before an application is run.
An application domain is the segment of reality for which a software system is developed. It is the background or starting point for the actual-state analysis and the creation of a domain model. An application domain can be an organization, a department within an organization, or a single workplace.
The AppDomain class implements a set of events that enable applications to respond when an assembly is loaded, when an application domain will be unloaded, or when an unhandled exception is thrown.
Separation of concerns
Actually creating a third project and adding project dependencies is the best way, because Separation of concerns isn't only a principle for classes but also for software modules. It creates some advantages:
Project Structure
Make sure you're not creating one big "utility" project, but rather domain-specific projects, like user management or addressbook.
In your case, it could be
Other Build Systems
When moving to continuous integration you'll need to use a better build system than Eclipse, but the principles are the same. You'll create small modules with minimal dependencies.
The most popular Build Systems for Java projects are Maven, Ant and Gradle. Each has its own way to define module dependencies.
Project references in Eclipse
To tell Eclipse about project dependencies, right click on the project, open the properties and switch to the project references. Here you could mark dependencies, so that code changes will take effect immediately without copying a JAR file manually.
Imho, this depends on your build system, not your IDE.
So, if you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With