On Mon, Jun 22, 2009 at 9:08 AM, Vineet Sinha <[email protected]> wrote:

>
>
> On Sun, Jun 21, 2009 at 5:23 PM, Hendy Irawan <[email protected]> wrote:
>
>> On Mon, Jun 22, 2009 at 3:38 AM, Vineet Sinha <[email protected]>wrote:
>>
>>
>>> Most of the current work at Eclipse seems to be using GWT for the Java
>>> to Javascript compiler. Do you see any way of merging the work, or
>>> will developers have to give up GWT for benefiting from j2s? And what
>>> are the benefits of j2s over GWT?
>>
>>
GWT's compiler and J2S' compiler are different, even though both are
extended from JDT compiler.

GWT's compiler is similar to C++ compiler, compiling *.java to script,
calculating the calling map, stripping out all unused or unreferenced
methods, linking and obfuscating all scripts into some big files.

Java2Script compiler is similar to Java compiler, compiling each *.java to a
*.js file, and compilation is done. All class information is left in *.js
without any stripping. To avoid too much *.js HTTP requests, some *.js are
packed into a bigger *.z.js file.

In brief, GWT and Java2Script is similar but under different design rules.

For more information about GWT and Java2Script compiler discussion, please
read some early posts:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/9b9cc255ab159586
http://inside.java2script.com/2007/05/14/java-to-javascript-compiler-discussion-1.html
http://inside.java2script.com/2007/05/14/java-to-javascript-compiler-discussion-2.html

One advantage of Java2Script over GWT would be the feature of dynamic class
loading and Java reflection. You can load a class manually by:
AClass.load("org.java2script.demo.ButtonTab", new ARunnable() {
    public void run() {
        try {
            Constructor constructor = getClazz().getConstructor(new Class[]
{ControlExample.class});
            Object inst = constructor.newInstance(new Object[]
{ControlExample.this});
            Tab tab = (Tab) inst;
            // ... do the following layout job
        } catch (Throwable e) {
            e.printStackTrace();
            throw (Error) e;
        }
    }
});
The loading procedure is asynchronous. As lazy loading is enabled, it is OK
to load complex applications.

Java2Script also supports native JavaScript inside Java source. It is
similar to GWT's JSNI. For examples:

    /**
     * For java native methods, if Java2Script native codes are given, the
     * native method will be generated when Java2Script compiler is enabled
     *
     * @j2sNative
     * var styleCSS =
"position:absolute;left:150px;top:5px;width:100px;height:40px;"
     *        +
"text-align:center;font-weight:bold;color:yellow;background-color:blue;"
     *        + "border:1px solid red;";
     * var hiEl = document.createElement("<div style=\"" +  styleCSS +
"\"></div>");
     * document.body.appendChild(hiEl);
     * hiEl.appendChild (document.createTextNode ("Hi!"));
     */
    native static void sayHi();

You can use @j2s* Javadoc or @J2S* annotation to control which method is
visible to JavaScript. For more information, you can visit
http://j2s.sourceforge.net/articles/tutorial-advanced-programming-on-j2s.html

For server communication, Java2Script has Simple RPC, similar to GWT RPC:
SimpleRPCRequest.request(new SendMessage() {

            @Override
            public void ajaxIn() {
                setTo(chatTo.getId());
                setMessage(msg);
                setThread((String) getData("threadID"));
            }

            @Override
            public void ajaxOut() {
                setData("threadID", getThread());
            }

            @Override
            public void ajaxFail() {
                System.out.println("Failed to send \"" + sendingMsg +
"\"!");
            }

});
SendMessage object is an instance of SimpleRPCRunnable. SimpleRPCRunnable
extends SimpleSerializable. SimpleSerializable instances will serialize its
public members and transport through the Internet. And SimpleRPCRunnable has
an ajaxRun() method, which contains native Java codes that are not compiled
to JavaScript. #ajaxRun method only visible in desktop mode or in server
mode.

There are desktop mode (native Java desktop application) and AJAX browser
mode (web RIA application) in Java2Script. In desktop mode, Thread are used
to emulate the RPC. In AJAX mode, XMLHttpRequest, <SCRIPT> or <IFrame> is
used for the RPC.

For Java language, both of GWT and Java2Script support Java 1.5. And both
support JUnit and others.

For development and deployment, both GWT and Java2Script support Eclipse
project and both support exporting application as normal Servlet WAR. In
Eclipse, you can create Java2Script projects by wizard or make existed Java
projects into Java2Script by property page. The Java2Script project will
compile both *.class and *.js at the same time. You can run or debug your
application as Java application. And you can also run your application as
Java2Script application. Java2Script plugin will generate an *.html file to
load the specific *.js and run it. After testing both in Java and JavaScript
mode, you can use the build.xml, which is provided by Java2Script, to pack
*.class or *.js into *.war. You can deploy the *.war to any given Servlet
containers.

Currently, Java2Script has no standalone compiler yet. So you can not build
your Java2Script applications outside Eclipse.

>From performance aspect, Java2Script applications is not running very fast.
It needs to be optimized by applying lazy loading pattern.

For overview of Java2Script architecture, you can visit
http://j2s.sourceforge.net/images/arch-of-j2s.png



>
>>>
>> I didn't realize that GWT compiler "standalone" is usable. Can you give
>> more information about this? From what I read on the net, GWT compiler
>> generates obfuscated code, and even if the obfuscation is disabled, the
>> generated JavaScripts are pretty much unusable from the developer
>> standpoint. (i.e. it was built to be used by GWT internals)
>>
>
> There is currently a whole ecosystem of tools and libraries built for GWT.
> Some of them:
> http://code.google.com/p/gwt-canvas/
> http://code.google.com/p/gwt-voices/
> http://code.google.com/p/gwt-log/
> http://code.google.com/p/gwt-templates/
>

It is also worthy to watch  "EclipseCon 09: RAP or GWT - Which Java-Based
AJAX Technology is for You? " ( http://live.eclipse.org/node/722 )


>
>
>>  >From my experience with the Flex work - there are a couple of
>>> challenges in bringing an already written Java app: the first is in
>>> having a compiler and the second is in having the libraries ported.
>>> Even though the flex work had its own compiler it benefitted from
>>> GWT's implementations for some of the JRE libraries. Perhaps the best
>>> solution might be to use the GWT compiler and j2s's libraries for swt
>>> - does this sound possible? Would it be hard?
>>
>>
Java2Script provides some common JRE libraries. And it is easy to add more
JRE libraries as you need. Just add some *.java files, and pack the compiled
*.js into JRE‘s *.js.

For porting Java2Script SWT library sources to GWT compiler, it is feasible
but it may require a lot of work. Java2Script compiler "knows" about some
SWT sources in compilation. It need more time to evaluate compiling
Java2Script's SWT sources in GWT.



>
>> It would be desirable if this is possible. That relieves Zhou from doing
>> redundant work that Google's doing (and will continue to do in foreseeable
>> future, I suppose) and can contribute more on e4, SWT/BE, and related
>> projects that can benefit him and Eclipse community at large including
>> myself. :-)
>>
>
> My guess is that there are limitations in both GWT's and j2s's compilers,
> which will prevent this from happening easily. But examining this might be
> worth doing.
>

Yes, both GWT and J2S' compilers have their limitations. Like some data type
conversion, floating point or big number computing may be incorrect. To make
a detailed list of this limitations may help developers to avoid such
defects. Most of these defects comes JavaScript specs.


>
> With the large community behind GWT - its compilers limitations are
> definitely easy to find - the good thing is that they have been very quickly
> working on removing their limitations. If j2s' libraries provide more
> capability than what we have currently - that's great. But it might make
> sense for us to hear more about its limitations.
>

Java2Script does not have large community. But using Java2Script, you can
use all those Java tools to develop native Java applications first, like
using SWT Designer to design SWT application. And later, you just make some
modifications of your sources or make no modifications, You applications run
in web browser Java2Script mode besides the native Java applications. In
such a way, we can reuse all existed community supports.

BTW: In early email, I mention supporting JFace. Here is the JFace demo link
: http://demo.java2script.org/jface/


>
>
> Vineet
>
>
>
> _______________________________________________
> e4-dev mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/e4-dev
>
>
Regards,
Zhou Renjian

--
http://webuzz.im/ Web IMs (G/A/M/Y)
http://j2s.sourceforge.net/ Java2Script
_______________________________________________
e4-dev mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/e4-dev

Reply via email to