Multi-part project in eclipse and more

Started by dijumx, August 04, 2011, 19:49:49

Previous topic - Next topic



So, I'm in the beginnings of a multiplayer java game which will require a client and a server.
Before I get started I wanted to know what is the best way to organise the files in eclipse given that I have:
Client Files
Common Files
Server Files

Where those files specific to the client are with client files, those specific to the server are with the server files, and those common to both are in the common files.

Seeing as I want to be able to export the client and server as separate jar files, what is the best way to organise the files? As separate projects or in one project with separate packages?

Also, I know this bit shouldn't be posted here but, how can I go about creating a Minecraft style standalone launcher (i.e. one which is run from a single jar file, not with extra parameters like getdown). I want to be able to customise the launcher so how would I include it in my projects file structure? (Note: I want to have both an appletLoader and a luanhcer for the client only, as the server won't use lwjgl)

P.S. I have very bad programming practices so some things which should be common knowledge may not be to me ;)


I'd recommend having three separate projects in Eclipse: "[game name]-common", "[game name]-client", and "[game name]-server".

Eclipse projects can be hierarchical. You can have add a project the the build path of another (right click on the project -> properties -> java build path ->projects). If a project has another on its build path, it is considered to "share" all of that code. Additionally, you can have settings enabled that will automatically package the other project with an export.

As for the launcher, that's actually a really, really easy problem to solve.

The most important thing to do is to consider the launcher an entirely separate application from your game. Do NOT mix the code of the launcher and the game, it'll make things more complicated and is entirely unnecessary.

First off, you "[game name]-client" project should contain neither the launcher or the applet. Instead, make your game so that it's basically fully-functioning, but have the display-setup code be delegated. So, once it's running, it will take advantage of the already created display, but be fully independent.

Next, make two new projects: "[game name]-launcher" and "[game name]-applet." Both of these will be relatively small. For example, the applet project will probably only contain a single class (your applet class, of course!) that handles initialization like any other lwjgl applet.

Your "launcher" project will be a bit more complicated, but not by much. Build your launcher application in Swing, use a JFrame, blah blah blah you have a nice little window with graphics and buttons that lets you do stuff. Now, simply tie code to an action (i.e., pressing the "play" button) that will close the launcher, and create a LWJGL display. Then, run your game in your "client" code.

Does all that make sense? It has numerous advantages. For example, you'll be able to modify either the game, the applet, or the launcher selectively, and you won't have to worry about screwing up anything else. Additionally, each of your exported jars (the applet or the launcher-based game) will not have unnecessary code for the other launcher system.


Ahh, Okay, Thank you for the advice on the project setup (or should that be projects ;) ) that will be a big help with keeping the game code nice and tidy!

With reference to the part I mentioned about a standalone Minecraft-style launcher, would this method produce a single jar capable of running without needing to be in the same directory as the external jars ( lwjgl.jar, natives/linux.jar etc)? I ask because I want to keep that "single jar" appearance of minecraft (you know, you only download a single Jar and the rest is handled in the application data directory)


You can actually contain the LWJGL jars inside your executable jar and everything will work fine. Java is handy that way.

However, you do need to have some external files in the OS's folder system: the native libraries.

LWJGL isn't a purely-java approach to OpenGL; it actually uses some operating system specific libraries. Unfortunately, you can't access them while they are packaged inside a jar (if you could, coding games would be much more wonderful but alas, such is life). You need to have them somewhere, and set a flag in the Java System libraries that LWJGL will uses when it is instantiated.

I actually wrote a very length post on my recommended way of managing the native files a while back, it's in this topic:,4006.0.html


So only the native files need to be external?

That's great thanks, no I can finally knuckle down and get to work on the game mechanics :D

Again, many thanks for your help.



Hi again,
I've started on my launcher, however I have become a bit concerned over how the code will actually work for a couple of reasons!

so, here is a section of code for the launcher:
private void startGame(){
		try {
			Display.setDisplayMode(new DisplayMode(800,600));
		} catch (LWJGLException e) {
		window = null;
		c = new Client();
	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource() == loginButton){
			//Login stuff Here
			//Then if okay, start game!

and the client:
public Client(){
		// init OpenGL here
		while (!Display.isCloseRequested()) {
			// render OpenGL here

Now, I'm a bit lazy when it comes to taking on big tasks with little guidance ( :D ), so this is really how far I've gotten with the playable side of things.
So, when I ran this the first time (without the lines
window.dispose(); window = null;
I noticed that the button which is pressed stays pressed (i.e. looks like it has frozen) so I'm concerned first of all about the threads which are being used!
Secondly, my code to destroy the JFrame after "Login" seems to be a bit off (my faut really, but is this the best way to do it?)
Finally, how do I pass the lwjgl Display from the launcher to the Client? I know it is working at the moment, but would it be better to run the display in a thread inside the client or in the client constructor?