Building the sources

There is a couple of things that should be done before building the sources. You only have this two things only once

The first is to decompress the file net.sf.j2s.lib/j2slib.zip. The easy way of doing so is to open net.sf.j2s.lib/build/build.xml in Ant view and run the j2s.unzip ant task

Second, the project net.sf.j2s.ajax requires JAVAX_SERVLET classpath variable to point to a .jar with the Java servlet specification. This is easy to infer looking at Eclipse Problems view.

You can create such a classpath variable pointing to Tomcat 5.0+'s servlet-apis.jar or plugin org.eclipse.tomcat's servlets.jar or other similar jar. Fortunately this is easy, first of all, locate the servlet-api.jar file in your computer. Probably you can find it on your Eclipse plugins directory (in my case it is located at eclipse/plugins/javax.servlet_2.5.0.v200910301333.jar). Also, this .jar file comes in any Java web server, like Tomcat (in the case of Tomcat 5.5 it is at common/lib/servlet-api.jar)

Now that you have located servlet-api.jar file in your computer, go to Eclipse Package Explorer view, right click on the project net.sf.j2s.ajax -> Build Path -> Configure Build Path.... Go to the "Libraries" tab, double click the JAVAX_SERVLET variable, then click on Variable... button and the click on New... button. In the "New Variable Entry" dialog, enter JAVAX_SERVLET as the variable name and the path to servlet-api.jar as the variable value:

Figure 11-8. Running the Java2Script Eclipse plugin

After this there should be no errors in the "Problems" Eclipse view and all projects should be rebuilt. The first time, this may take a while. Remember that there are two compilers compiling some large projects like java.lang, java.util package, swt, and other java toolkits both to .class and to javascript.

As said in the previous section, Java2Script plugin contains two different kind of java sources. In one side we have the J2S eclipse plugin itself in projects net.sf.j2s.core and net.sf.j2s.ui and in the other side we have projects like net.sf.j2s.java.core and net.sf.j2s.java.org.eclipse.swt that are actually java libraries to be compiled into javascript and used by our Java2Script applications developed with the Java2Script plugin.

Both kind of projects will be built automatically [1] so we only have to save our files to impact the changes. Nevertheless, if we are modifying files that will be compiled to JavaScript, like the ones in project net.sf.j2s.java.core, we should also rebuild j2slib. It is easy. Just open net.sf.j2s.lib/build/build.xml in Ant view and run the j2s.pack.lib ant task:

Figure 11-9. Packing j2slib

Important: Please remember to always run ant j2s.pack.lib when modifying Java files to be compiled to JavaScript before launching the Eclipse plugin like showed in next section.

Remember, as with any Java project, if you want to force project rebuild, you can always goto menu "Project -> Clean" and clean all projects: also be sure that "Project -> Build Automatically" is checked for automatically building when you change a file.

Notes

[1]

Only make sure that menu Project->Build Automatically is checked.