trouble getting tutorial #6 ajax app to work

  • kedaar

    kedaar - 2007-03-27

    Hi there,

    I am having trouble getting both the tutorial ajax application (from tutorial #6) plus my own simple ajax application to work.  The applications both work using "run->as java application" but not "run->as javascript application". 

    I am using eclipse 3.2 and all the previous tutorial code has worked fine.

    However, for the app that I wrote the actionlistener is not triggered (although the gui comes up) and in the tutorial application I just get the message
    [Java2Script] Error in loading bin/net/sf/j2s/examples/RSSReader.js!

    For the record:
    - I have enabled the compiler
    - enabled net.sf.j2s.ajax and I do not get any compile errors.  I added the packages directly to my project instead of adding their projects to my build path.
    - added swt support (the run->as java app works)

    What I have not done was add j2s-ajax-core.jz.  This is because:
    - when I open the Java2Script Builder property page I am able to "add resources"
    - I see only console.css and swt-shell-title.css
    - The window filters out all other files.  I even tried renaming the extension to .js and it still did not appear.

    I am assuming the problems are because of the jz file.  Any suggestions are much appreciated.

    be happy

    • kedaar

      kedaar - 2007-03-27

      Here is the error message I get with my application, the actionlistener is called but I dont think the http request is ever sent:
      Java2Script] Error in loading ../../../../eclipse3.2/eclipse/plugins/net.sf.j2s.lib_1.0.0.v420/j2slib/java/io/ByteArrayInputStream.js!
      [Java2Script] Error in loading ../../../../eclipse3.2/eclipse/plugins/net.sf.j2s.lib_1.0.0.v420/j2slib/java/io/ByteArrayOutputStream.js!
      [Java2Script] Error in loading ../../../../eclipse3.2/eclipse/plugins/net.sf.j2s.lib_1.0.0.v420/j2slib/java/io/DataOutputStream.js!
      [Java2Script] Error in loading ../../../../eclipse3.2/eclipse/plugins/net.sf.j2s.lib_1.0.0.v420/j2slib/java/net/URL.js!
      [Java2Script] Error in loading bin/javax/xml/parsers/DocumentBuilderFactory.js!

    • Zhou Renjian

      Zhou Renjian - 2007-03-27

      Hi Kedaar,

      For a quick answer, tutorial #6 may be out of date, as lots of things were already changed.

      I suggest you to delete .j2s file that is under the project root. And then re-enable Java2Script compiler. "[Java2Script] Error in loading ..." should disappear.

      Tutorials will be updated in these days. Keep tuned.

      Zhou Renjian

    • Zhou Renjian

      Zhou Renjian - 2007-03-27

      and similar *.js are missing from Java2Script java.* core library. There are no such classes implemented in Java2Script. So these error complaints are known.

      You can ignore these messages by adding a line:
      ClazzLoader.ignore(["", "$.ByteArrayInputStream", "$.ByteArrayOutputStream", "", "javax.xml.parser.DocumentBuilderFactory");
      after ClazzLoader.setPrimaryFolder(...)

      • kedaar

        kedaar - 2007-03-27

        When I delete the .j2s file I get another error:
        [Java2Script] Error in loading bin/org/eclipse/swt/widgets/Composite.js!

        When I re-add the j2s swt library, I get the same errors as earlier - but the gui always gets rendered.  I dont mind the errors as I am not using any of those classes, but the trouble is that the http request object is not being sent nor the response received.

        Do you have a working project with any simple gui or RIA making a servlet call with the j2s api?  I am supposed to finish evaluating j2s by the end of the week to see if our project can use it instead of going with Seam or others. 

        Here is my class below, built with the eclipse visual editor:

        package test;

        import java.util.Collection;

        import net.sf.j2s.examples.HttpRequestCallBackSWTAdapter;

        import org.eclipse.swt.SWT;
        import org.eclipse.swt.layout.FillLayout;
        import org.eclipse.swt.layout.GridData;
        import org.eclipse.swt.layout.GridLayout;
        import org.eclipse.swt.widgets.Button;
        import org.eclipse.swt.widgets.Composite;
        import org.eclipse.swt.widgets.Display;
        import org.eclipse.swt.widgets.Label;
        import org.eclipse.swt.widgets.Shell;
        import org.eclipse.swt.widgets.Table;
        import org.eclipse.swt.widgets.TableColumn;
        import org.eclipse.swt.widgets.Text;

        import ajax.HttpRequest;

        public class NameSearch extends Composite {

            private Table table = null;
            private Label label = null;
            private Text text = null;
            private Button button = null;
            private Text textArea = null;
            private Collection clients;

             * @param args
            public static void main(String[] args) {
                // TODO Auto-generated method stub
                /* Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments)
                 * for the correct SWT library path in order to run with the SWT dlls.
                 * The dlls are located in the SWT plugin jar. 
                 * For example, on Windows the Eclipse SWT 3.1 plugin jar is:
                 *       installation_directory\plugins\org.eclipse.swt.win32_3.1.0.jar
                Display display = Display.getDefault();
                Shell shell = new Shell(display);
                shell.setLayout(new FillLayout());
                shell.setSize(new Point(400, 450));
                new NameSearch(shell, SWT.NONE);

                while (!shell.isDisposed()) {
                    if (!display.readAndDispatch())

            public NameSearch(Composite parent, int style) {
                super(parent, style);

            private void initialize() {
                GridData gridData3 = new GridData();
                gridData3.heightHint = 160;
                gridData3.widthHint = 170;
                GridData gridData = new GridData();
                gridData.horizontalSpan = 4;
                gridData.heightHint = 160;
                Label filler = new Label(this, SWT.NONE);
                GridLayout gridLayout = new GridLayout();
                gridLayout.numColumns = 5;
                label = new Label(this, SWT.NONE);
                label.setText("Enter Last Name");
                text = new Text(this, SWT.BORDER);
                text.addModifyListener(new {
                    public void modifyText( e) {
                            String url = "http://localhost:8080/search/search";
                            final HttpRequest request = new HttpRequest();
                  "GET", url, true);                   
                            request.registerOnReadyStateChange(new HttpRequestCallBackSWTAdapter() {
                                public void swtOnComplete() {
                                    System.out.println ("response received");
                            System.out.println ("request sent");                   

                button = new Button(this, SWT.NONE);
                table = new Table(this, SWT.NONE);
                Label filler2 = new Label(this, SWT.NONE);
                Label filler1 = new Label(this, SWT.NONE);
                textArea = new Text(this, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
                TableColumn tableColumn = new TableColumn(table, SWT.NONE);
                tableColumn.setText("First Name");
                TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
                tableColumn1.setText("Last Name");
                TableColumn tableColumn2 = new TableColumn(table, SWT.NONE);
                this.setSize(new Point(342, 400));

        }  //  @jve:decl-index=0:visual-constraint="10,10"

    • Zhou Renjian

      Zhou Renjian - 2007-03-28

      Here is an AJAX snippet:

      Create a Java2Script AJAX application, and create the following class:\*checkout*/j2s/trunk/tests/net.sf.j2s.test.ajax/src/net/sf/j2s/test/ajax/

      Run it as Java application may have errors, if you configure Crimson as your XML parser. You may configure Xerces as the default XML parser.

      Run it as Java2Script application in IE, you should get a list of RSS items.

      MAKE sure that Java2Script application is run in IE. Because local HTML page in IE may have the privilege to access any remote server page. But in Firefox/Mozilla/Opera, local HTML application can not access any other remote pages, which may result no request is sent. In such situations, you have to deploy the j2slib/**/*, bin/**/*.js and *.html to your same server that servlets are deployed. And then load it there, XMLHttpRequest in Java2Script will send out the requests.

      XMLHttpRequest is limited on cross site scripting (XSS). If you need XSS supports, please use Simple RPC, you got an GTalk demo on the front page of ,  which is also a demo of Simple RPC with XSS supports.

      • kedaar

        kedaar - 2007-03-28

        When I run LoadingRSS as a java app it works fine - I get the returned elements printed to the console. 

        When I run as javascript or open the html file in IE - it doesnt seem to work in both cases.    The words "continue!" are printed which shows that the request was sent, but nothing else is printed.

        Here is my .j2s file, perhaps something on the build path is not correct?
        #Java2Script Configuration
        #Wed Mar 28 10:00:32 EDT 2007

        Two Issues:

        1)  With Google talk, when I deploy the war file to jboss and visit the localhost url the login gui pops up.  When I choose the default user I get a exception : connection timed out in the jboss console.  This may be caused by the firewall?
        2) When I add the project to Eclipse, there is a problem with the build path - the ECLIPSE_SWT path variable for the build path is empty.  So I deleted it and readded SWT support as a library.  Now however the compiler is telling me that there is a missing method SimpleRPCRunnable.url() that needs to be implemented in many of the classes.  So I added a dummy method that returns "" to the GTalkRunnable which got rid of the compile errors.  When I run as java app I get the gui but when I try to login with either the default user or my gmail id I get "failed to login" - the same message I saw when I used the war file.

        Of the two apps, I am most interested in getting LoadinRSS to work as I can use this with my demo code easily.  Any suggestions?  Can you send me a zip file containing your LoadingRSS package for eclipse 3.2?

        Thanks for the help

    • Zhou Renjian

      Zhou Renjian - 2007-03-28

      First suggestion: Make a refresh Eclipse SDK and Java2Script installation (Download , unzip it and copy them ). And use workspace that is relative folder plugins. And open LoadRSS or GTalk demo project again. And try it again.

      It seems that your environment has previous version of net.sf.j2s.ajax plugin. If you have install previous version of Java2Script, please do remove those plugins.

      I will test installations from again to locate the bug.

      And please join to get some more quick answers from more developers. Or email me by the email address given by


    • Zhou Renjian

      Zhou Renjian - 2007-03-28

      Oo! You are still using 1.0.0 M4?
      Current Java2Script release is 1.0.0 M5. Please remove your M4 plugins and install the new release.


    • kedaar

      kedaar - 2007-03-28

      I have tried deploying everything to jboss as per your last message to avoid the browser permissions. 

      In both browsers I am getting a message (with IE I have to open the file in FrontPage to get a similar message):
      ClazzLoader is not defined
      [Break on this error] ClazzLoader.packageClasspath ("java", "../../../../eclipse3.2/eclipse/plugins/ne...

      Any thoughts?

    • Zhou Renjian

      Zhou Renjian - 2007-03-28

      Please modify your *.html adjusting those *.js paths to your absolute path.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks