Run multiple java main methods in eclipse -
I am running Eclipse 3.5 and I have a constant problem that I have 6 -7 clicks to test my program. Instead, click the Play button.
The problem is that I am writing a networking application and thus I have run configuration for "server" and "client". Then, to test my program, I have to start the server, then a customer, then another client etc. Is it automated automatically in a run configuration?
You can call the main method directly to any class, for example, if you have a server and client class and you have a If you want to run the server and two clients, then this is what you can do.
public class server {public zero main (last string .... Args) {last server s = new server (); S.config ($ args); S.run (); }} Public class client {public zero principal (final string ... $ Args) {end customer C = new customer (); C.config ($ args); C.run (); }} Public class Test_ServerClient {Public Zero Main (last string ... $ Args) {Server.main ('server1.cfg'); Client.main ('client1.cfg'); Client.main ('client2.cfg'); }}
Done!
Well, almost almost.
Though one seems to want to make some delay before you call the customer's main call. All servers and clients will run on the same JVM. In most cases (that is, you want to test your conversation and do nothing with class loading because they will behave in different ways when they are not on the same JVM), it should be fine. If you really want to run it on different JVM, then you can use the ant to run them.
Something like this:
& lt; Project name = "test server client" default = "test" basedir = "." & Gt; & Lt; Goal name = "test" & gt; & Lt; Java classname = "my.Server" & gt; & Lt; Arg value = "server1.cfg" /> & Lt; Classpath & gt; & Lt; Pathelement location = "dist / test.jar" /> & Lt; Pathhelm Path = "$ {java.class.path}" /> & Lt; / Classpath & gt; & Lt; / Java & gt; & Lt; Java classname = "my.Client" & gt; & Lt; Arg value = "client1.cfg" /> & Lt; Classpath & gt; & Lt; Pathelement location = "dist / test.jar" /> & Lt; Pathhelm Path = "$ {java.class.path}" /> & Lt; / Classpath & gt; & Lt; / Java & gt; & Lt; Java classname = "my.Client" & gt; & Lt; Arg value = "client2.cfg" /> & Lt; Classpath & gt; & Lt; Pathelement location = "dist / test.jar" /> & Lt; Pathhelm Path = "$ {java.class.path}" /> & Lt; / Classpath & gt; & Lt; / Java & gt; & Lt; / Target & gt; & Lt; / Project & gt;
So you can just run this ant and this is it.
Hope this will be helpful.
Comments
Post a Comment