You can call the main method of any class directly. For example, if you have Server and Client class and you want to run one server and two client, here is what you may do.
public class Server {
public void main(final String ... $Args) {
final Server S = new Server();
S.config($Args);
S.run();
}
}
public class Client {
public void main(final String ... $Args) {
final Client C = new Client();
C.config($Args);
C.run();
}
}
public class Test_ServerClient {
public void main(final String ... $Args) {
Server.main('server1.cfg');
Client.main('client1.cfg');
Client.main('client2.cfg');
}
}
Done!
Well, almost. You may want do some delay before calling main of the client just to make sure server is up and running properly.
One think though. All the Server and Clients will be run on the same JVM. In most case (that you just want to test its interaction and have nothing to do with class loading as that will behave differently when they are/are not on the same JVM), this should be fine. If you really want o make it run on different JVM, you may use Ant to run them instead.
Something like this:
<project name="TestServerClient" default="test" basedir=".">
<target name="test">
<java classname="my.Server">
<arg value="server1.cfg"/>
<classpath>
<pathelement location="dist/test.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
<java classname="my.Client">
<arg value="client1.cfg"/>
<classpath>
<pathelement location="dist/test.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
<java classname="my.Client">
<arg value="client2.cfg"/>
<classpath>
<pathelement location="dist/test.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
</project>
So you can just run this ant and that is it.
Hope this helps.