开发者

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

开发者 https://www.devze.com 2023-01-25 10:21 出处:网络
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.

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 v开发者_StackOverflow社区ariable 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


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.


You might create a separate project for your common JSON code. Using subversion, svn:externals allow a neat integration on the source level. Importing the common code as jar file is another approach.


If you're using maven, you could create a local maven project containing all the classes you might need in different projects and add this dependency to your pom.xml which requires these classes.

0

精彩评论

暂无评论...
验证码 换一张
取 消