Shared resources in a Java project for server and client packages

后端 未结 4 1082
伪装坚强ぢ
伪装坚强ぢ 2021-01-15 10:14

I have a Java project that has both server and client packages. In addition I have a library package.

I use eclipse and have put everything in a single Java proje

4条回答
  •  梦毁少年i
    2021-01-15 10:49

    I use eclipse and have put everything in a single java project, each section server,client and library are in separate packages, the problem is that when I export, everything gets added to the Jar file.

    This is the part that intrigued me, why are you exporting something that has both the client and the server? From a client-server perspective they are going to be distributed separately.

    Do I actually need three different projects? It will become a little unwieldy as everything is actually related and I would like to keep them together.

    Thanks to how IDEs can now manage dependencies across projects/modules, I don't think it looks as bad as you picture it. For example you can work simultaneously on the server code, and use its classes and interfaces from your client code, and reference JARs produced by the server project.

    I'd like also to add that a 'Project' isn't the broadest encapsulation of code either, there is still a 'Workspace' that can contain a number of related 'Projects'. Other IDEs go for other wordings like 'Module' instead of 'Project'.

    Closing thoughts:

    For the least impedance path, I think you should separate the client and the server parts into two projects, and do the same think for the shared library in case you are compiling it from source i.e, not a 3rd party JAR.

    So in the end of the day you will have 3 'products' from the compilation process and distribute them where they belong, with the 'library' duplicated on both distribution sides.

提交回复
热议问题