|
| 1 | +SwingJS distribution README.txt |
| 2 | + |
| 3 | +3/15/2018 Bob Hanson hansonr@stolaf.edu |
| 4 | + |
| 5 | +SwingJS has been successfully tested in Eclipse Neon and Oxygen on Mac and Windows platforms. |
| 6 | +(No reason to believe it would not also work for Linux; just haven't tried that recently.) |
| 7 | + |
| 8 | +INSTALLATION INSTRUCTIONS |
| 9 | + |
| 10 | +Eclipse Neon or higher is necessary. |
| 11 | + |
| 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 |
| 24 | + |
| 25 | +https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar?raw=true |
| 26 | + |
| 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 |
| 35 | + |
| 36 | +/Applications/Eclipse.app/Contents/Eclipse/dropins |
| 37 | + |
| 38 | +2. Restart Eclipse and check for the presence of the plug-in at |
| 39 | + help...about Eclipse...installation details...Plug-ins...(wait several seconds for tabulation) |
| 40 | + |
| 41 | +search for "j2s" to find j2s.sourceforge.net Java2Script Core |
| 42 | + |
| 43 | +If that is not there, you don't have net.sf.j2s.core.jar in the proper directory. |
| 44 | + |
| 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. |
| 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: |
| 78 | + |
| 79 | +.j2s |
| 80 | + |
| 81 | +containing simply: |
| 82 | + |
| 83 | +j2s.compiler.status=enable |
| 84 | + |
| 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 |
| 87 | + |
| 88 | + org.eclipse.jdt.core.javabuilder |
| 89 | + |
| 90 | +to |
| 91 | + |
| 92 | +net.sf.j2s.core.java2scriptbuilder |
| 93 | + |
| 94 | + |
| 95 | +-------------------- |
| 96 | +Building the project |
| 97 | +-------------------- |
| 98 | + |
| 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. |
| 115 | + |
| 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 | +---------------- |
| 137 | + |
| 138 | +A full site with many examples is at https://chemapps.stolaf.edu/swingjs/site |
| 139 | + |
| 140 | +Falstad applets are in https://github.com/BobHanson/SwingJS-Examples |
| 141 | +and appear at https://chemapps.stolaf.edu/swingjs/site |
| 142 | + |
| 143 | +VARNA development is at https://github.com/BobHanson/VARNA |
| 144 | +working site is https://chemapps.stolaf.edu/swingjs/varna |
| 145 | + |
| 146 | +Physlets development is at https://github.com/BobHanson/Physlets-SwingJS |
| 147 | +working site is https://chemapps.stolaf.edu/swingjs/physlets |
| 148 | + |
| 149 | +Phet applets have not been put on GitHub yet. |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +As of Feb. 17, 2018, we are actively converting a variety of functioning Java applets. |
| 154 | + |
| 155 | +The physlets Animator, Doppler, and Optics are working. |
| 156 | + |
| 157 | +As of Jan. 2, 2018, all known Java-to-JavaScript issues have been dealt with. |
| 158 | +Efficient Google Closure Compiler compression is in place. |
| 159 | + |
| 160 | +As of Dec. 17, 2017, SwingJS is fully operational in its "version 2" format, |
| 161 | +which includes fully qualified method, array, and number typing. |
| 162 | + |
0 commit comments