среда, 28 декабря 2011 г.

Debugging GWT client-side code with the remote server

Today I realize that debugging client-side code on JBoss web-server is very time-expensive task. And I decided to improve this process with help of Development Mode feature provided by GWT team. This mode should reduce time spent to debug client-side code. From the box development mode launcher can be started only with embedded Jetty instance. But in my project I need to make some initialization steps before launching the server. At first sight you shoud assume that just following google recomandations can reach you to the destination. But it's not quite true.

1) First of all you should install GWT plugin for your browser, but don't worry about it. With first start of your GWT applicaotion in development mode it will be suggested to you to install this GWT extension.

2) Then we must to run our remote server. The following lines of code should help you to start your own Jetty Server (in your case it could be JBoss, apache or something else):

final String host = "127.0.0.1";
final int port = 8008;

final Server server = new Server();
final Connector connector = createConnector(host, port);
server.setConnectors(new Connector[]{connector});

final WebAppContext context = new WebAppContext();
context.setServer(server);
context.setContextPath("/");
context.setWar(localBuild.getCanonicalPath());
server.addHandler(context);

try {
  server.start();
} catch (Exception e) {
  log.error("Failed to start jetty server. " + e.getMessage(), e);
  return;
}

try {
  server.join();
} catch (InterruptedException e) {
  log.error("Main thread interrupted. " + e.getMessage(), e);
}

Where the "localBuild" variable is a path to your WAR directory.

3) Let's assume that your GWT application name is MyApp and GWT-module file MyApp.gwt.xml exists at the directory com/myapp/MyApp.gwt.xml.
Now we can start our dev-mode process, which should connect to server. We can do it with the following command:


java com.google.gwt.dev.DevMode -noserver -war  localBuild -port 8008 -startupUrl "http:// 127.0.0.1:8008/MyAppGWT.html" com.myapp.MyApp


-noserver means that you want to use your own servlet-container.
-port is remote port of your web-server
-startupUrl is FULL url of your GWT-application.
and last argument is path to your GWT-module config.

Notice that "MyAppGWT.html" is starting point file of you application, which you can find at your WAR-directory. And another important observation is that your classpath directory should contains
gwt-2.0.3/gwt-dev.jar 
gwt/gwt-user.jar
path to /src/ directory of your GWT application


4) Add to your browser GWT-extension all urls, which it should handle (in our case it's just "127.0.0.1" and may be localhost)

That's all. Now you can enjoy hotswapping (by refreshing the page) your client-side java classes instead of compiling all of them to javascript-code.

I've spent half a day googling and researching sources of com.google.gwt.dev.DevMode to solve this task. I hope this short description could help somebody.

Relative links:
http://code.google.com/intl/ru-RU/webtoolkit/doc/latest/DevGuideCompilingAndDebugging.html
http://stackoverflow.com/questions/2629297/is-it-possible-to-debug-gwt-client-code-on-a-remote-server-using-intellij-9-comm



Комментариев нет:

Отправить комментарий