Can I use VAJ version 2.0 to develop servlets and test or debug it without starting web server? Is there any third party provide tools that do this and can be integrated into VAJ?

Oliver Springauf

I did this quite a lot. Sun's Servlet DevKit (JSDK) includes a web server (sun.servlet.http.HttpServer) that you can use. In practice, give your servlet class a main method like

import java.lang.reflect.Method;

...

public static void main(java.lang.String[] args) {
  String sMyURL = 
      "http://localhost:8080/servlet/pkg.test.myservlet";

  // this variable must be set by you
  String sMyBrowser = 
      "c:ProgrammeNetscapeCommunicatorProgram
etscape.exe";

  try {
    boolean success = false;
    // Throw an exception if we are not in the VisualAge IDE
    Class.forName("com.ibm.uvm.abt.edit.TestFrame");
    Runtime.getRuntime().exec(sMyBrowser + " " + sMyURL);
    Class serverStarterClass = 
        Class.forName("sun.servlet.http.HttpServer");
    Method method = 
        serverStarterClass.getMethod("main", 
                                     new Class[] {String[].class});
    method.invoke(serverStarterClass, 
                  new Object[] {new String[] {"-p", "8080"}});
  }
  catch (Throwable e) {
    System.err.println(e);
  }
}

You can then start your servlet by executing its main(), which starts the web server and your browser. The JSDK server is only for testing, it lacks most features of other servlet engines (like aliases, url rewriting, ...) There are two minor inconveniences with this method: you have to find your own way to configure your servlet, and earlier versions of the JSDK server did not serve files (only servlets). I could imagine that it's also possible to integrate other servlet engines (like Apache's) into VAJ.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact