Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 76 additions & 34 deletions sources/net.sf.j2s.core/dist/README.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
SwingJS distribution
This is the main README file for the Java2Script/SwingJS distribution

https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins/README.txt
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/README.txt

8/6/2018 Bob Hanson hansonr@stolaf.edu
8/12/2018 Bob Hanson hansonr@stolaf.edu

Java2Script 3.2.2.03 introduces and checks more Java 8 capabilities.
Use
The dist/dropins folder has been renamed dist/swingjs

https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs

It holds the key files that are needed for a J2S project (see below).


Java2Script 3.2.2.03 introduces and checks more Java 8 capabilities. Use

eclipsec -clean

Expand All @@ -26,22 +32,24 @@ This includes
java.util.stream.*
default methods in interfaces

All projects compiled under 3.1.1 need to be recompiled using the Java2Script 3.2.1 transpiler, as
All projects compiled under 3.1.1 need to be recompiled using the Java2Script 3.2.x transpiler, as
described below. Note that if you use /** @j2sNative */ calls to interface methods that are singlets,
you no longer need to add qualifications (such as $O) to them. It should be no problem to leave them
those methods all take just $ as a qualifier. It should be no problem to leave them
qualified, though, as the transpiler creates qualified and unqualified aliases.

There are situations where this use of unqualified method names can run into problems. For example, in
java.util.stream.ReferencePipeline, there are three different declarations of the functional interface
method "accept". They were just for erro reporting and have been removed.
There are occasional situations where this use of $-unqualified method names can run into problems.
For example, in java.util.stream.ReferencePipeline, there are three different default declarations
of the functional interface method "accept". They are just for error reporting and have been removed.
My guess that this is a rarity, but I am not sure.


SwingJS has been successfully tested in Eclipse version Neon-Photon on Mac and Windows platforms.
(No reason to believe it would not also work for Linux; just haven't tried that recently.)
Java 8 is the target Java version for transpilation. Please report any missing classes or strange
errors.


3/15/2018 Bob Hanson hansonr@stolaf.edu

net.sf.j2s.core_3.2.1.jar replaces net.sf.j2s.core_3.1.1.jar

These versions differ only in their internal workings relative to Eclipse.
Expand All @@ -51,19 +59,14 @@ the standard Eclipse java builder, org.eclipse.jdt.core.javabuilder.

For v. 3.2.1, to get started with SwingJS, all you need are:

1) the latest transpiler from

https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins

2) the latest JavaScript-site.zip from
1) the latest transpiler (net.sf.j2s.core.jar) and run-time (Swingjs-site.zip) from

https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/dist
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs

3) an empty .j2s file in your project directory. (The v.3.2.1 transpiler will fill this in with
a default .j2s configuration when it runs the first time.)
2) an empty .j2s file in your project directory. (The Java2Script transpiler will fill this in with
a default .j2s configuration when it runs the first time. Or, you could use the one in /dist to start)


NOTE! If you are updating to 3.2.1 from 3.1.1, be sure to open your .project file and change the
NOTE! If you are updating to 3.2.x from 3.1.1, be sure to open your .project file and change the
builder name from net.sf.j2s.core.java2scriptbuilder back to org.eclipse.jdt.core.javabuilder
or your project will no longer compile.

Expand All @@ -89,22 +92,48 @@ that match the standard .class files created by the Eclipse Java compiler itself
Note that both Java .class files (in bin/) and JavaScript .js files (in site/swingjs/j2s) are
created automatically anytime you do any building of your project.

The easiest thing to do is to copy the contents of the dist/ directory

https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist

into your project directory. It contains the following directories:

swingjs/
-- contains the necessary Eclipse drop-in as well as the run-time
-- ver/ subfolder holds older versions
tools/
-- contains ant-contrib.jar, used by build-site.xml
libjs/
-- empty; reserved for foo.zip equivalents of dependency foo.jar files
-- these will be unzipped into site/ by build-site.xml
resources/
-- empty; reserved for non-java resources your program might need
-- these will go into site/swingjs/j2s by build-site.xml

and files:

.j2s -- a starter j2s configuration file
build-site.xml -- run this to build the site/ directory before or after you
update your Java code.


The following instructions include instructions for doing some of this manually:

1. Copy net.sf.j2s.core.jar from

https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs

specifically:

https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar?raw=true
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs/net.sf.j2s.core.jar?raw=true

into your eclipse/dropins directory.

Also provided in that directory is a ver/ directory with previous core files.
It is recommended that you not use them. If you do, be sure to remove their _x.x.x version
signature from their file name, or some versions of Eclipse will have to be
entirely reinstalled every time you change versions. We do not know why this is necessary,
but it appears to be. This is an Eclipse bug. So just always use dist/dropins/net.sf.j2s.core.jar.
These files have names that are purposely unversioned because some versions of Eclipse
will have to be entirely reinstalled every time you change versions if the names are different
from version to version. We do not know why this is necessary, but it appears to be.
This is an Eclipse bug. So just always use dist/swingjs/net.sf.j2s.core.jar.

On Mac systems, the Eclipse directory is generally

Expand All @@ -117,7 +146,7 @@ Search for "j2s" to find j2s.sourceforge.net Java2Script Core

If that is not there, you don't have net.sf.j2s.core.jar in the proper directory.

Note relating to updating to 3.2.1 from 3.1.1 version of Java2Script:
Note relating to updating to 3.2.x from 3.1.1 version of Java2Script:

If the version on this readout does not match the version that is
reported at the end of each .js file created:
Expand All @@ -127,8 +156,7 @@ If that is not there, you don't have net.sf.j2s.core.jar in the proper directory
then there is no real problem, but you can correct that by restarting
Eclipse once with the -clean flag.




----------------------------------
Creating a new J2S/SwingJS project
----------------------------------
Expand All @@ -145,11 +173,17 @@ All source code must be available. (Source code from decompiling .class files wi
Installing the SwingJS JavaScript version of the Java Virtual Machine
---------------------------------------------------------------------

Chrome users should consider using WebServer for Chrome to serve local files. It is very
simple to set up.

https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb?hl=en


All of the JavaScript produced will be in the project site/ directory.
You must prepopulate this site with all the JavaScript required by the
JavaScript version of the JVM. The most recent version of site/ is at

https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip?raw=true
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip?raw=true

Occasional additions to the java.* classes are made to the above-mentioned zip file.

Expand Down Expand Up @@ -211,6 +245,13 @@ Info = {
allowjavascript: true
}

You can add

core: "NONE",

to that to prevent the use of core/coreswingjs.z.js and make life easier for yourself
while debugging.

These Info key/value pairs are equivalent to Java applet parameters. Use Info.args for the main(args[])
parameters. For instance:

Expand Down Expand Up @@ -239,10 +280,11 @@ If you do that, be sure to use the OpenJDK version. For example:

http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes

Most of the code in the SwingJS project started with
Java 6-b14 or 6-b27. Build your project, then delete these Java files, because, should this file be added
to an updated verison of SwingJS, you should probably use the one provided, not your own. Your choice.
Most of the code in the SwingJS project started with Java 6-b14 or 6-b27. The goal is to
move these all to Java8 OpenJDK versions.

Build your project, then delete these Java files, because, should this file be added
to an updated version of SwingJS, you should probably use the one provided, not your own. Your choice.

----------------
Working projects
Expand Down
81 changes: 81 additions & 0 deletions sources/net.sf.j2s.core/dist/build-site.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0"?>
<!--
BH 2018.08.12

- requires tools/ant-contrib.jar

- creates the site/ directory if it does not exist
- unzip libjs/*.zip into site/swingjs/j2s
- unzips swingjs/SwingJS-site.zip into site/
- copies non-java resources from resources/ into site/swingjs/j2s

-->

<project name="swingjs-project" default="tosite" basedir="."
xmlns:if="ant:if"
xmlns:unless="ant:unless">

<target name="tosite">

<!-- input directories -->

<!-- location of ant-contrib.jar -->
<property name="tools.dir" value = "tools" />

<!-- SwingjS_site zip file (could be varied if versioning is needed) -->
<property name="swingjs.zip" value="swingjs/SwingJS-site.zip" />

<!-- location of third-party jar contents as precompiled zipped .js files to copy to site/ -->
<property name="libjs.dir" value="libjs" />

<!-- non-Java resources to copy to site/ -->
<property name="resource.dir" value="resources" />

<!-- output directories -->

<property name="site.dir" value="site" />
<property name="j2s.dir" value="${site.dir}/swingjs/j2s" />

<!-- <for ...> construct needs ant-contrib.jar -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${tools.dir}/ant-contrib.jar" />
</classpath>
</taskdef>

<!-- unzip all libjs zip files into site

all zip files placed in libjs will be processed

-->

<for param="file.zip">
<path>
<fileset dir="${libjs.dir}" includes="*.zip"/>
</path>
<sequential>
<unzip src="@{file.zip}" dest="${site.dir}" overwrite="true"/>
</sequential>
</for>

<!-- unzip SwingJS-site.zip

we do this separately, as we want it done last

-->

<unzip src="${swingjs.zip}" dest="${site.dir}/" overwrite="true"/>

<!-- transfer resources -->

<echo> Copying ${resource.dir} files into ${j2s.dir} </echo>
<copy todir="${j2s.dir}">
<fileset dir="${resource.dir}">
<include name="**"/>
</fileset>
</copy>

</target>


</project>
1 change: 0 additions & 1 deletion sources/net.sf.j2s.core/dist/dropins/timestamp

This file was deleted.

1 change: 0 additions & 1 deletion sources/net.sf.j2s.core/dist/dropins/ver/3.2.2/timestamp

This file was deleted.

19 changes: 19 additions & 0 deletions sources/net.sf.j2s.core/dist/libjs/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SwingJS distribution -- libjs directory

This directory can be used to hold pre-compiled *.zip files that
have root directories swingjs and swingjs/j2s. They will be
unzipped into the site/ directory by build-site.xml.

Generally these files would be derived from .jar files that your
program uses. If your program has jar dependencies, you will need to
find the source for those, compile it, and then zip the resulting
.js files into xxxx.zip. The ANT task that might do this should look
something like this:

<target name="zipjson">
<!-- org.json.simple -->
<property name="json.zip" value="${libjs.dir}/jsonsimple-site.zip" />
<echo> Zipping up ${json.zip} </echo>
<zip destfile="${json.zip}" basedir="${site.dir}" includes="swingjs/j2s/org/json/**" />
</target>

6 changes: 6 additions & 0 deletions sources/net.sf.j2s.core/dist/resources/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SwingJS distribution -- resources directory

This directory can be used to hold non-Java files that your program
needs to run -- data files, for instance. Files in it will be copied to
the site/ directory by build-site.xml.

Binary file not shown.
1 change: 1 addition & 0 deletions sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20180812102716
Binary file not shown.
1 change: 1 addition & 0 deletions sources/net.sf.j2s.core/dist/swingjs/ver/3.2.2/timestamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20180812102716
Binary file not shown.
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
5 changes: 5 additions & 0 deletions sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// j2sCore.js (based on JmolCore.js

// BH 8/12/2018 adding J2S.onClazzLoaded(i,msg) hook for customization
// for example, the developer can look for i=1 (pre-core) and add core files selectively
// or set System.$props["user.home"] to a desired directory before (i=1) or just after (i=2) core file loading
// BH 8/6/2018 fix for Java Application start-up when not headless in Java 8
// BH 7/21/2018 fix for static{thisApplet.__Info.width=300} not working
// BH 7/2/2018 10:00:49 PM fix logic for FileReader for Chrome
Expand Down Expand Up @@ -52,6 +55,8 @@ self.J2S

});

J2S.onClazzLoaded || (J2S.onClazzLoaded = function(i, msg) {console.log([i,msg])});

if (!J2S._version)
J2S = (function(document) {
var z = J2S.z || 9000;
Expand Down
7 changes: 6 additions & 1 deletion sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// TODO: CharacterSequence does not implement Java 8 default methods chars() or codePoints()
// It is possible that these might be loaded dynamically.

// BH 8/12/2018 3.2.2 adding J2S.onClazzLoaded hook for Clazz loaded
// BH 8/11/2018 3.2.2 Clazz.newLambda removed
// BH 8/9/2018 3.2.2 adds newLambda(...'S')
// BH 8/6/2018 3.2.2 sets user.home to be "https://./"
Expand Down Expand Up @@ -5610,8 +5611,12 @@ var newMethodNotFoundException = function (clazz, method) {
if (!Clazz._loadcore || J2S._coreFiles.length == 0) {
if (!Clazz._quiet)System.out.println("Clazz: No core files to load -- check Info.core");
}
for (var i = 0; i < J2S._coreFiles.length; i++)

J2S.onClazzLoaded && J2S.onClazzLoaded(1, "Clazz loaded; loading J2S._coreFiles " + J2S._coreFiles.length);
for (var i = 0; i < J2S._coreFiles.length; i++) {
Clazz.loadScript(J2S._coreFiles[i]);
}
J2S.onClazzLoaded && J2S.onClazzLoaded(2, "Clazz loaded; core files loaded");


})(Clazz, J2S);
Expand Down
12 changes: 11 additions & 1 deletion sources/net.sf.j2s.java.core/srcjs/swingjs2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10655,6 +10655,9 @@ return jQuery;
})(jQuery,document,"click mousemove mouseup touchmove touchend", "outjsmol");
// j2sCore.js (based on JmolCore.js

// BH 8/12/2018 adding J2S.onClazzLoaded(i,msg) hook for customization
// for example, the developer can look for i=1 (pre-core) and add core files selectively
// or set System.$props["user.home"] to a desired directory before (i=1) or just after (i=2) core file loading
// BH 8/6/2018 fix for Java Application start-up when not headless in Java 8
// BH 7/21/2018 fix for static{thisApplet.__Info.width=300} not working
// BH 7/2/2018 10:00:49 PM fix logic for FileReader for Chrome
Expand Down Expand Up @@ -10707,6 +10710,8 @@ self.J2S

});

J2S.onClazzLoaded || (J2S.onClazzLoaded = function(i, msg) {console.log([i,msg])});

if (!J2S._version)
J2S = (function(document) {
var z = J2S.z || 9000;
Expand Down Expand Up @@ -13447,6 +13452,7 @@ if (!J2S._version)
// TODO: CharacterSequence does not implement Java 8 default methods chars() or codePoints()
// It is possible that these might be loaded dynamically.

// BH 8/12/2018 3.2.2 adding J2S.onClazzLoaded hook for Clazz loaded
// BH 8/11/2018 3.2.2 Clazz.newLambda removed
// BH 8/9/2018 3.2.2 adds newLambda(...'S')
// BH 8/6/2018 3.2.2 sets user.home to be "https://./"
Expand Down Expand Up @@ -19047,8 +19053,12 @@ var newMethodNotFoundException = function (clazz, method) {
if (!Clazz._loadcore || J2S._coreFiles.length == 0) {
if (!Clazz._quiet)System.out.println("Clazz: No core files to load -- check Info.core");
}
for (var i = 0; i < J2S._coreFiles.length; i++)

J2S.onClazzLoaded && J2S.onClazzLoaded(1, "Clazz loaded; loading J2S._coreFiles " + J2S._coreFiles.length);
for (var i = 0; i < J2S._coreFiles.length; i++) {
Clazz.loadScript(J2S._coreFiles[i]);
}
J2S.onClazzLoaded && J2S.onClazzLoaded(2, "Clazz loaded; core files loaded");


})(Clazz, J2S);
Expand Down