Java2Script Getting Started
- Aug 16, 2006
This getting started article shows how to run normal Java applications as Java2Script applications.
We assume you already know Java and know how to write and debug normal Java programs inside Eclipse. And we aslo assume you know how to run SWT applications and JUnit tests inside Eclipse.
3 Steps for Java2Script's "Hello World"
For your first Java2Script application, It's about 3 steps for you to follow.
Step 1: Create your "Hello World" Java application. You should test your "Hello World" Java application does print "Hello World" before you continue.
: Enable Java2Script compiler. There is "Java2Script Builder" tab page in Java project's properties page.
: Select your "Hello World" *.java and run it as "Java2Script Application":
If everything is OK, a "J2S Console" view will be created, and the same "Hello World!" will be printed:
If you would like to study how Java2Script works, you can right click inside the J2S console for contextmenu "View Source" item for generated HTML sources. For more technical details, please check out and read the lastest sources from J2S SVN repository or ask questions on j2s-development mail-list.
Running Java2Script SWT Applications
For running SWT applications as "Java2Script Application", you need to add "swt" library to the Java project. To do so, open "Java2Script Builder" page, and select "Resources" in the tree, then click the enabled "Add Libraries" button to open up "Libraries Selection" dialog, select "swt".
Run your SWT application as "Java2Script Application". For example, some windows with different style will be open inside "J2S Console". For example:
Running Java2Script Unit Tests
You can run JUnit tests in Java2Script mode. To do so, you must add the Java2Script "junit" libraries in the "Java2Script Builder" page, and then run JUnit tests as "Java2Script Unit Test". Unlike Eclipse JUnit tests, which are run in JFace/SWT graphical mode, Java2Script unit tests run in text console mode currently.
Java2Script Applications with Referenced Projects
If you split your application into different projects and add required projects on the build path in "Java Build Path" tab page of Java project properties pages, you should also need to "Add Projects" in the "Java2Script Builder" tab page before you run Java2Script application to make everything work correctly.
What Role is Java2Script Playing
Java2Script is aiming at providing a way to convert existed RCP into RIA without any or with small modifications of the original sources. Java2Script is trying not to interrupt the normal desktop application development.
, or stay tuned with more coming articles.