@@ -9,11 +9,22 @@ INSTALLATION INSTRUCTIONS
99
1010Eclipse Neon or higher is necessary.
1111
12- 1. net.sf.j2s.core.jar should be copied from
12+ -----------------------------------------------------------
13+ Installing the Java2Script transpiler as an Eclipse plug-in
14+ -----------------------------------------------------------
15+
16+ The Java2Script transpiler for SwingJS is in net.sf.j2s.core.jar. It parses the .java code and
17+ creates .js files that match the standard .class files created by the Eclipse Java compiler.
18+
19+ Note that both Java .class files (in bin/) and JavaScript .js files (in site/swingjs/j2s) are
20+ created automatically anytime you do any building of your project.
21+
22+
23+ 1. Copy net.sf.j2s.core.jar from
1324
1425https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar?raw=true
1526
16- to your eclipse/dropins directory.
27+ into your eclipse/dropins directory.
1728
1829Do not use net.sf.j2s.core_x.x.x.jar for this, as, if you do that, some versions of Eclipse will have to be
1930entirely reinstalled every time you change versions. We do not know why this is necessary,
@@ -24,43 +35,93 @@ On Mac systems, the Eclipse directory is
2435
2536/Applications/Eclipse.app/Contents/Eclipse/dropins
2637
27- 2. restart Eclipse and check for the presence of the plug-in at
38+ 2. Restart Eclipse and check for the presence of the plug-in at
2839 help...about Eclipse...installation details...Plug-ins...(wait several seconds for tabulation)
2940
3041search for "j2s" to find j2s.sourceforge.net Java2Script Core
3142
3243If that is not there, you don't have net.sf.j2s.core.jar in the proper directory.
3344
34- 3. Create an Eclipse Java project for your work, if you have not done so already.
45+
46+ ----------------------------------
47+ Creating a new J2S/SwingJS project
48+ ----------------------------------
49+
50+ Create an Eclipse Java project for your work, if you have not done so already.
3551If your source code is not all already in src/, navigate to the project...properties...Java Build Path...source
3652and add all the source directories you need.
3753
38- 4. Create in the Eclipse project the file:
54+ Note that your project must not include any Jar file based dependencies.
55+ All source code must be available. (Source code from decompiling .class files will work.)
56+
57+
58+ ---------------------------------------------------------------------
59+ Installing the SwingJS JavaScript version of the Java Virtual Machine
60+ ---------------------------------------------------------------------
61+
62+ All of the JavaScript produced will be in the project site/ directory.
63+ You must prepopulate this site with all the JavaScript required by the
64+ JavaScript version of the JVM. The most recent version of site/ is at
65+
66+ https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip?raw=true
67+
68+ Occasional additions to the java.* classes are made to the above-mentioned zip file.
69+
70+ Simply download and unzip that file into your project, creating a top-level site/ directory.
71+
72+
73+ -------------------------------------------
74+ Enabling the Java2Script/SwingJS transpiler
75+ -------------------------------------------
76+
77+ 1. Create in your Eclipse project the file:
3978
4079.j2s
4180
4281containing simply:
4382
4483j2s.compiler.status=enable
4584
46- 5. Modify the .project file to indicate the j2s transpiler is to be used,
47- changing the buildSpec buildCommand from
85+ 2. Edit the .project file to indicate that the j2s transpiler is to be used
86+ rather than the standard Java compiler by changing the buildSpec buildCommand from
4887
4988org.eclipse.jdt.core.javabuilder
5089
5190to
5291
5392net.sf.j2s.core.java2scriptbuilder
5493
55- 6. All of the JavaScript produced will be in the project site/ directory.
56- You must prepopulate this site with all the JavaScript required by the
57- JavaScript version of the JVM. The most recent version of site/ is at
5894
59- https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip?raw=true
95+ --------------------
96+ Building the project
97+ --------------------
6098
61- Occasional additions to the java.* classes are made to the above-mentioned zip file.
99+ Build your project as you normally would. Java class files will be created as usual in the bin/ directory.
100+ JavaScript equivalents of these files will be created in the site/swingjs/j2s directory. You might have to
101+ do a project refresh to see these site files.
102+
103+ Do take a look at the .js files created. You will notice that they are all the methods and fields of your
104+ Java project *except* final static constants. SwingJS does not recreate those by name; it just uses them.
105+ (The only thing this should affect is that java.lang.reflect.Field does not indicate these names.)
106+
107+
108+ ----------------------------------------------
109+ Testing the JavaScript version of your project
110+ ----------------------------------------------
111+
112+ The J2S transpiler will automatically set up for you in site/ a sample HTML papge for any class that subclasses
113+ JApplet or contains a public void main(String[] args) method. You will want to associate those files with
114+ an external HTML browser. We recommend Firefox.
115+
116+ Since you will be running AJAX locally within these browsers, you may need to enable local file reading in your
117+ browser. Instructions for doing that can be found at http://wiki.jmol.org/index.php/Troubleshooting/Local_Files
118+
119+
120+ ------------------------
121+ Adding more Java classes
122+ ------------------------
62123
63- If you find you are missing a class, please contact me (Bob Hanson) at hansonr@stolaf.edu.
124+ If you find you are missing a Java class, please contact me (Bob Hanson) at hansonr@stolaf.edu.
64125You can try adding these yourself by **temporarily** adding one or more of the
65126Java classes found at http://grepcode.com to the proper package. If you do that, be sure
66127to use the OpenJDK version. Most of the code in the SwingJS project started with Java 6-b14 or 6-b27.
0 commit comments