Search code examples
javaspringarchitectureclient-servercode-sharing

Using one Java source file in two different projects, both under development


I am developing a Spring (Java framework for server-side web-development)web application, which will respond to another client-side Java application(which uses socket communication) by a JSON object. At the same time, I'm working on both server-side and client-side Java applications.

The problem is that I have a bunch of files(say, a Json variable interfaces) that are being used at both projects. For now, I have duplicate copies of that interface, in different packages in the two projects. But this causes inconsistency, because I have to update the both files whenever I need to make a change in the interface.

Does anyone have a neat solution for this?

Thanks


Solution

  • You should treat your shared code at the package level and not the file level.

    You should create a package of interface definitions that are used by both the client and server side of your architecture and whenever that package changes, both sides will have to change accordingly.

    EDIT:

    I wasn't explicit about it but zellus' suggestion about importing the common code as a jar is a good one.