1- SwingJS distribution README.txt
1+ SwingJS distribution README.txt
2+
3+ 3/15/2018 Bob Hanson hansonr@stolaf.edu
24
35SwingJS has been successfully tested in Eclipse Neon and Oxygen on Mac and Windows platforms.
46(No reason to believe it would not also work for Linux; just haven't tried that recently.)
@@ -7,69 +9,147 @@ INSTALLATION INSTRUCTIONS
79
810Eclipse Neon or higher is necessary.
911
10- 1. net.sf.j2s.core_3.1.1.jar should be copied to the eclipse/dropins
11- directory **AS net.sf.j2s.core.jar dropping the version info**
12- because otherwise Eclipse will not recognize an update.
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
14- We do not know why this is necessary, but it appears to be. If you leave
15- the version in the name, Eclipse will not be able to replace it with a
16- newer version later. From what we can tell.
25+ https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar?raw=true
1726
18- On Mac systems, this directory is
27+ into your eclipse/dropins directory.
28+
29+ Do 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
30+ entirely reinstalled every time you change versions. We do not know why this is necessary,
31+ but it appears to be. If you leave the version in the name, Eclipse will not be able to replace it with a
32+ newer version later. From what we can tell. So just always use dist/dropins/net.sf.j2s.core.jar.
33+
34+ On Mac systems, the Eclipse directory is
1935
2036/Applications/Eclipse.app/Contents/Eclipse/dropins
2137
22- 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
2339 help...about Eclipse...installation details...Plug-ins...(wait several seconds for tabulation)
2440
2541search for "j2s" to find j2s.sourceforge.net Java2Script Core
2642
2743If that is not there, you don't have net.sf.j2s.core.jar in the proper directory.
2844
29- 3. Create an Eclipse Java project for your work, if you have not done so already.
30- If your source code is not all already in src/, navigate to the project...properties...Java Build Path...source
31- and add all the source directories you need.
3245
33- 4. Create in the Eclipse project the file:
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.
51+ If your source code is not all already in src/, navigate to the project...properties...
52+ Java Build Path...source and add all the source directories you need.
53+
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:
3478
3579.j2s
3680
3781containing simply:
3882
3983j2s.compiler.status=enable
4084
41- 5. Modify the .project file to indicate the j2s transpiler is to be used,
42- 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
4387
44- org.eclipse.jdt.core.javabuilder
88+ org.eclipse.jdt.core.javabuilder
4589
4690to
4791
4892net.sf.j2s.core.java2scriptbuilder
4993
50- 6. All of the JavaScript produced will be in the project site/ directory.
51- You must prepopulate this site with all the JavaScript required by the
52- JavaScript version of the JVM. The most recent version of site/ is at
5394
54- https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip?raw=true
95+ --------------------
96+ Building the project
97+ --------------------
5598
56- 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 page for any class
113+ that subclasses JApplet or contains a public void main(String[] args) method. You will want to
114+ associate those files with an external HTML browser. We recommend Firefox.
57115
58- If you find you are missing a class, please contact me (Bob Hanson) at hansonr@stolaf.edu.
59- You can try adding these yourself by **temporarily** adding one or more of the
60- Java classes found at http://grepcode.com to the proper package. If you do that, be sure
61- to use the OpenJDK version. Most of the code in the SwingJS project started with Java 6-b14 or 6-b27.
62- Build your project, then delete these Java files, because you do not necessarily want your Java
63- code using that version, just JavaScript.
116+ Since you will be running AJAX locally within these browsers, you may need to enable local
117+ file reading in your browser. Instructions for doing that can be found at
118+ http://wiki.jmol.org/index.php/Troubleshooting/Local_Files
119+
120+
121+ ------------------------
122+ Adding more Java classes
123+ ------------------------
124+
125+ If you find you are missing a Java class, please contact me (Bob Hanson) at hansonr@stolaf.edu.
126+ You can try adding these yourself by **temporarily** adding one or more of the Java classes found
127+ at http://grepcode.com to the proper package in your project. For example, java/awt.
128+
129+ If you do that, be sure to use the OpenJDK version. Most of the code in the SwingJS project started with
130+ Java 6-b14 or 6-b27. Build your project, then delete these Java files, because you do not necessarily
131+ want your Java code using that version, just JavaScript.
132+
133+
134+ ----------------
135+ Working projects
136+ ----------------
64137
65138A full site with many examples is at https://chemapps.stolaf.edu/swingjs/site
66139
140+ Falstad applets are in https://github.com/BobHanson/SwingJS-Examples
141+ and appear at https://chemapps.stolaf.edu/swingjs/site
142+
67143VARNA development is at https://github.com/BobHanson/VARNA
68144working site is https://chemapps.stolaf.edu/swingjs/varna
69145
70146Physlets development is at https://github.com/BobHanson/Physlets-SwingJS
71147working site is https://chemapps.stolaf.edu/swingjs/physlets
72148
149+ Phet applets have not been put on GitHub yet.
150+
151+
152+
73153As of Feb. 17, 2018, we are actively converting a variety of functioning Java applets.
74154
75155The physlets Animator, Doppler, and Optics are working.
0 commit comments