I’m writing a client and server application. Right now I’ve just been developing it on my own, so I have written it as one Eclipse project, organized into Java packages (org.myorg.server, org.myorg.client, org.myorg.networksystem, etc.). The project deploys to a single jar file. Then, the client is an applet, so I simply point the applet code parameter at org.myorg.client.ClientApplet inside the jar file, whereas when I run the server, it’s a command line application and I just run:
java -jar MyJar.jar
org.myorg.server.ServerApplication
Well, I need to clean up its structure and improve the build process. I also want to separate the jar files, so that an user does not have access to a copy of the server built right into the jar file as it is now.
I want to use a continuous integration server such as CruiseControl. It would be really cool if I only needed to check my code into the SVN repository; then the CruiseControl server would grab the code, compile it and package it into separate jars, then deploy the server jar onto my dedicated server and run it, and also deploy the client jar onto my web server so that the applet is updated.
I can figure out CruiseControl. My current issue is how to separate the code. It’s nicely separated into client and server packages, but then there are some shared packages such as the network protocol. Should I separate my project into 3 projects for client, server, and common? Should I do something else? I was considering writing Ant build files by hand, but I would really like to stay in Eclipse.
How can I best organize my code to meet these goals?
(by the way, sorry if this question is confusing, I think I’m having a hard time putting into words all of the different questions swirling around my head)
If seems you already know what you need to do, however, If you want CruiseControl to compile and package the code, then you will need to use a tool like Ant, or possible Maven, Gradle, or some other build tool, in order to have it do what you want. Even if you have a build tool package the code you can still use Eclipse to build and run everything.
I am not sure how familiar you are with Ant, but using Ant will give you more control over the build process at the expense of requiring defining the process. Other tools like Maven and Gradle have a prescribed way of structuring the code that reduces the amount of configuration for a build, and in the case of Maven I am not sure that one can change how it expects the project layout to be. Gradle on the other hand can have its defaults change.
As far as organization, I think separating the code into client, server, and the network protocol shared by the client and server, as you have mentioned, would be good. I don’t use Eclipse, so I am not sure how that would be done. You could just package the client and server into separate JARS with the class files from the network protocol module in both, or just make three JARS.