We have for all our tests a method which starts a Jetty Server to publish and test the Web-Services:
@Before
public void startJettyAndloadWSDL() throws Exception {
String port = System.getProperty("jetty.port");
server = new Server(Integer.valueOf(port));
WebAppContext webapp = new WebAppContext();
webapp.setSecurityHandler(getSecurityHandler()); // this is a local function in my test
webapp.setContextPath("/");
webapp.setWar(System.getProperty("jetty.war"));
server.setHandler(webapp);
// Is there an option somewhere to say "start Jetty in Debug mode"?
server.start();
service = new MyServiceToTest(new URL("http://127.0.0.1:" + port + "/WS/MyServiceToTest/1?WSDL"),
new QName("urn:myservicetotest.services.mycompany.com/1", "MyService")).getMyServicePort();
}
Is there any way to say Jetty to start in Debug Mode in order to put a breakpoint in Eclipse?
The test is run using Maven externally to Eclipse, then perhaps it is better to make a remote debugging in that case?
We do not want to have a big link with Eclipse, then it is why we start the jetty in all JUnits tests.
We cannot change the embedded Jetty because the continous integration needs it and we will not maintain two version of the JUnit tests (automated or manual).
The solutions I found are:
1 – From maven with remote debug:
Start the test with the following commmand (from maven site):
and then start the Eclipse remote debug on port 8000.
But this solution is not very clever: as the jetty is embedded, I have to manually start the remote debugging of Eclipse and it needs some synchronisation when I start maven from the command line (maven is not integrated to eclipse in that project).
The best way we finally use is:
2 – From Eclipse Junit
I just execute the Junit Test from Eclipse in debug mode and this is just perfect: the jetty startup method does not need any option for
debug modeas it is the JVM which starts in runtime or debug mode.I do not need to use the WTP jetty in the Eclipse, I just had to define the properties in the test like:
and the breakpoint stops where I want.
The only configuration is in Eclipse and it will not change our code.