GithubHelp home page GithubHelp logo

java2script / java2script Goto Github PK

View Code? Open in Web Editor NEW
54.0 54.0 31.0 1.69 GB

Java2Script provides an Eclipse Java to JavaScript transpiler (source-to-source compiler) and a nearly complete JavaScript implementation of the Java runtime environment (including AWT and Swing).

Home Page: http://java2script.github.io/java2script

License: Other

HTML 0.16% Java 94.42% JavaScript 5.27% CSS 0.15% Batchfile 0.01% PHP 0.01% SCSS 0.01%
awt compiler cross-compiler eclipse eclipse-plugin java java-applet java-virtual-machine java2script javascript javascript-transpiler language migration swing swt transpiler

java2script's Introduction

Note

java2script/java2script is the overall master of the project. However, all active devlopment should be forked from BobHanson/java2script, as that is the current development fork. That said, pushing to java2script/java2script is done regularly, so BobHanson/java2script should not ever be too far ahead of java2script/java2script.

These notes are for Java developers who want to convert their Java applets or Java applications to JavaScript, allowing continued, simultaneous one-source development of both Java and JavaScript.

A discussion of application limitations and features is at https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs/differences.txt

Developers of java2script/SwingJS itself should read README-developers.md

Bob Hanson ([email protected])

About java2script/SwingJS

java2script/SwingJS is not a one-time "port" to JavaScript. It is a system that allows real-time Java-to-JavaScript conversion within Eclipse, with immediate JavaScript testing and debugging in a browser based on code development in Java. Using the java2script/SwingJS Eclipse plug-in, both Java .class files and their equivalent .js files are created simultaneously.

java2script/SwingJS includes an Eclipse plug-in (technically a "drop-in"), net.sf.j2s.cor

e.zip (see https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs), along with a JavaScript version of the Java Virtual Machine (SwingJS, https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip) to allow the rapid and automated production of browser-ready JavaScript versions of Java applications and applets.

Working Examples

Examples of SwingJS applied to allow single-source Java+JavaScript development include:

Jmol-SwingJS https://github.com/BobHanson/Jmol-SwingJS

JalView-JS https://www.jalview.org/jalview-js

MathePrisma https://www.matheprisma.de/ (over 600 applets)

Open Source Physics (OSP) https://github.com/OpenSourcePhysics/osp/tree/swingJS

TrackerJS https://physlets.org/tracker/trackerJS

QuickStart

See https://github.com/BobHanson/java2script/tree/master/sources/net.sf.j2s.core/dist and the README file in that directory.

Relationship to Alternatives

A number of alternative methods of using Java to create JavaScript have been proposed and developed to one extent or another. The following discussion compares java2script/SwingJS to these other methods, based on my own limited understanding of them as of Dec. 2019.

Google Web Toolkit

http://www.gwtproject.org/ "GWT is a development toolkit for building and optimizing complex browser-based applications. Its goal is to enable productive development of high-performance web applications without the developer having to be an expert in browser quirks, XMLHttpRequest, and JavaScript."

I know that GWT has been successfully employed for relatively simple application conversions from Java to JavaScript. It implements a reasonably large set of JRE classes [http://www.gwtproject.org/doc/latest/RefJreEmulation.html], but not really a sufficiently large number of classes to support developed Java projects. For example, Class.forName() is missing, so that means no dynamic class loading; File, FileInputStream, and FileOutputStream are missing, meaning no standard file i/o. Most significantly, java.awt and javax.swing are missing. This means that whatever user interface is built must be built from scratch with JavaScript only in mind.

In contrast, java2script/SwingJS supports an HTML5-based "platform look and feel" (plaf) that leverages all the native features of HTML5 to match the Java AWT and Swing UI. For example, virtually all the Swing and AWT frame, window, panel, dialog, border, and layout classes have been implemented. There are no additional specialized classes that a developer needs to add to his or her project. Rather than using a working Java program as the basis for a JavaScript-specific application, as in GWT, java2script/SwingJS allows for parallel co-production of distributable Java and JavaScript equivalent applications.

TeaVM

http://teavm.org/ "TeaVM is an ahead-of-time compiler for Java bytecode that emits JavaScript and WebAssembly that runs in a browser. Its close relative is the well-known GWT. The main difference is that TeaVM does not require source code, only compiled class files. Moreover, the source code is not required to be Java, so TeaVM successfully compiles Kotlin and Scala."

I can only find a very few examples of TeaVM use. But from what I can see, TeaVM is still at "concept" stage. It appears that they are hand writing "pseudo" Java as they go. For example, we see at

https://github.com/konsoletyper/teavm/tree/master/classlib/src/main/java/org/teavm/classlib

that "java.awt" contains three classes: TColor, TDimension, and TPoint. TColor has exactly four methods: getRed(), getGreen(), getBlue(), and getAlpha(). It appears to me that the developer has hand-written a decent collection of 800 files as org.teavm.classlib.java. Apparently, the idea is that you would take your Java project and swap in these pseudo-java classes. But this is not scalable. One can't expect a 100,000-line Java program to be retooled or limited to this small hand-crafted set of classes.

In the author's own words, "There are Java APIs that are impossible to implement without generating inefficient JavaScript. Some of these APIs are: reflection, resources, class loaders, and JNI. TeaVM restricts usage of these APIs. Generally, you’ll have to manually rewrite your code to fit into TeaVM constraints." OK, but java2script/SwingJS implements reflection, does just-in-time class loading, uses property files and resource bundles, loads images, and much more. There are only minimal constraints that require modifying Java code. Yes, modal dialogs and Thread.sleep() do require refactoring a bit, but we have had no problem with this on over 500,000 lines of code in multiple projects. So it doesn't seem to be a major impediment.

CheerpJ

https://www.leaningtech.com/cheerpj/ "CheerpJ converts Java applications or libraries into JavaScript. Works on bytecode, does not require access to the source code. Compatible with 100% of Java including reflection and dynamic classes. Existing Java archives can be converted to Web applications effortlessly"

This sounds terrific. And truly it is. I am very impressed! Basically run the Java byte code in JavaScript. The Java Reporter demonstration at https://www.leaningtech.com/cheerpj/demos/ crashed both Firefox and Chrome for me, so I cannot really evaluate what I see here. But I have played with the JFiddle at https://javafiddle.leaningtech.com/, and it is pretty amazing.

The primary differences between java2script/SwingJS and CheerpJ, to the best of my knowledge, include:

  • fast start-up time. SwingJS applications generally start within a second or two, sometimes within 100 ms
  • small downloads, anywhere from about 800K for a small non-GUI program to 10 MB for a full-blown Swing application (JSmol)
  • class-level just-in-time dynamic class loading; no need to retrieve entire JAR files just for a few methods
  • leveraging features of HTML5 and modern JavaScript rather than just painting a canvas the way Java does natively
  • delivering an easily interpretable and debuggable JavaScript translation of Java classes, with little or no obscurification (unless that is desired)
  • well-designed JavaScript-friendly Java core classes that leverage the considerable power of JavaScript
  • open source and completely extensible

History - 2019-

SwingJS is now more than just "Swing"+JavaScript. AWT applets and applications are now supported. A test suite of over 500 AWT applets has been used to refine the AWT runtime classes with great success. Many thanks to Karsten Blankenagel (University of Wuppertal) for access to this source code set.

Examples include:

MathePrisma (http://www.matheprisma.uni-wuppertal.de/) This site is still using the Java applets as of 2019.03.12; JavaScript versions still in development.

History - 2017-

https://github.com/BobHanson/java2script/tree/hanson1 (development branch)

https://github.com/BobHanson/java2script (master)

Current development "Version 3 development master" involves a completely rewritten transpiler (2017) “CompilationParticipant” that follows the Eclipse Java compiler. The implementation nearly perfectly emulates the Java Virtual Machine. It includes fully qualified methods, compile-time method binding, generic methods and classes, Java 8 lambda functions and streams, Java reflection and dynamic class loading for efficient modular just-in-time performance, Java Swing components, modal and nonmodel dialogs, audio, jpdf, the AWT event thread, and many other added packages. Java applications and applets can both be run in JavaScript in any browser.

Version 3 also implements real-time creation of HTML test files for immediate JavaScript testing of any changes made to the Java code. Basically, when the source file is saved in Eclipse (Photon), the JavaScript updates automatically, and a reload of the page in the browser shows the changes immediately. This makes for very easy side-by-side Java and JavaScript debugging.

Unlike Version 2, Version 3 requires minimal reworking of Java classes - primarily just for performance and threading* reasons, maximizing JavaScript performance without compromising any Java performance and making Java-to-JavaScript conversion almost trivial. (Of course, we are still finding occasional bugs in the transpiler and run-time "JavaScript-JVM.")

*Note that java2script/SwingJS cannot support Thread.wait(), Thread.notify(), or Thread.sleep(). Nonetheless, in all cases we have found simple state-based alternatives that essentially reproduce this behavior in JavaScript using javax.Swing.Timer. These methods work equally well in Java and JavaScript, requiring just a bit of redesign of Java methods.

Examples include:

Physlets (https://github.com/BobHanson/Physlets-SwingJS) conversion to JavaScript by Wolfgang Christian ([email protected]) and Bob Hanson (in progress).

Jmol-SwingJS https://github.com/BobHanson/Jmol-SwingJS (code only)

Varna https://github.com/BobHanson/VARNA and https://chemapps.stolaf.edu/swingjs/varna

History - 2010-2016

https://github.com/java2script/java2script (stable master)

Ported from SourceForge by Zhou Renjian, developed further by Zhou Renjian and Udo Borkowski (primarily) as "Version 2.0".

Extensively used by Bob Hanson in 2012-2016 for the conversion of Jmol/java to JSmol/javascript (http://jmol.sourceforge.net/), leading to extensive distribution and widespread use on the web. As of 3/2018, still the only known widely-available java2sript application.

Developed further in 2016 by zhou Renjian, Udo Borkowski, Bob Hanson, Andrew Raduege, Nadia El Mouldi, and Paul Falstad (http://www.falstad.com) for the first round of post-JSmol application of java2script, adding javax.swing classes and dubbed "SwingJS". Used by Bob Hanson during 11/2016 for conversion of the PhET gas applications applets.

Version 2 allowed extensive development of JavaScript versions of Java applets, including JSmol, Falstad applets, and PhET applets. However, this version did not produce "fully qualified" method signatures, resulting in error-prone and performance-reducing run-time binding of methods. Java class loading procedures were not consistent with the sequence of events used by the Java class loader, and parameter and array typing was minimal. Thus, while functional, Version 2 was not fully generalizable and required extensive reworking of Java code to be "java2script compliant."

Synchronized with https://github.com/BobHanson/java2script as the stable master version in 2018.

Examples include:

PhET, Falstad, and other tests https://chemapps.stolaf.edu/swingjs/phet/site/swingjs/examples Initial SwingJS tests converting AWT to Swing in Java, then transpiling.

JSmol: https://chemapps.stolaf.edu/jmol/jsmol Non-AWT, Non-Swing version, our initial application of Java2Script technology.

Falstad Math and Physics Applets (https://www.falstad.com/mathphysics.html) Source available.

History - 2005-2010

https://sourceforge.net/projects/j2s (last updated 6/2010)

Initially developed by Zhou Renjian (aka "Josson Smith", [email protected], 2005-2017), Soheil Hassas Yeganeh ([email protected], 2006), Sal Ferro ([email protected], 2006), Sebastian Gurin ([email protected], 2008), and others. The project was a "proof-in-concept" that saw limited actual application.

java2script's People

Contributors

abego avatar benzoid avatar bobhanson avatar nikeshyad avatar warownia1 avatar zakki avatar zhourenjian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

java2script's Issues

new Boolean("false") should be false

Java is different from JavaScript in that in Java, new Boolean(string) is true only when string.equalsIgnoreCase("true"), but in JavaScript, new Boolean(string) is true for anything other than "" or null.

Solution is to create in the j2s runtime a binding for Boolean.from(string), and then convert all instances of "new Boolean " to "Boolean.from" in Java2ScriptCompiler.outputJavaScript(...)

// the need is to have new Boolean(string), but that won't work with native Boolean
// so instead we have to do a lexical switch from "new Boolean" to "Boolean.from"
Boolean.from=Clazz.defineMethod(Boolean,"from",
($fz=function(name){
return new Boolean(typeof name == "string" ? name.equalsIgnoreCase("true") : !!name);
},$fz.isPrivate=true,$fz),"~S");

Fixed for j2sSwingJS.js 7/2016.

$fz?

Does the global variable $fz do something? I have removed it from SwingJS and JSmol and see no loss of functionality. I see that it has something to do with private methods -- setting the .isPrivate field. But what is the situation that this is trying to address? I have not seen in any of the code I have dealt with.

Java 9 not supported

When the Java project is using a Java 9 JRE Eclipse shows these errors:

- The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project
- The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

When changing to a Java 8 JRE the errors disappear.

prematurely executed inline code blocks

Using j2s-2.0.0-v20160624-eclipse-4.5

This example is in an anonymous function, but the problem is the same without that complication:

	Test_6 x = new Test_6() {
		String zz = "zz";
		String[] xx0 = { "x1", "x2" };
		{
				System.out.println(" xx0[0]=" + xx0[0]);
		}
	};

should report:

xx0[0]=x1

but it instead throws an error that xx0 is undefined.

The transpiled code looks like this:

c$.$Test_4$1$ = function () {
  if (Clazz.isClassDefined('test.Test_4$1')) return test.Test_4$1;
  Clazz.pu$h();
  c$ = Clazz.decorateAsClass(function () {
    Clazz.prepareCallback(this, arguments);
    this.zz = 'zz';
    this.xx0 = null;
    {
        System.out.println(Clazz.castObjectAs('xx0[0]=' + this.xx0[0], 'String'));
    }
    Clazz.instantialize(this, arguments);
  }, test, 'Test_4$1', test.Test_6);
  Clazz.prepareFields(c$, function () {
    this.xx0 = Clazz.newArray( - 1, [
      'x1',
      'x2'
    ]);
    {
        System.out.println('xx0[0]=' + this.xx0[0], 'String'));
    }
  });
  var rc = c$;
  c$ = Clazz.p0p();
  return rc;
};

A simple solution would be to remove all inline anonymous code blocks prior to running Clazz.initialize, and to have those only in the prepareFields call:

c$.$Test_4$1$ = function () {
  if (Clazz.isClassDefined('test.Test_4$1')) return test.Test_4$1;
  Clazz.pu$h();
  c$ = Clazz.decorateAsClass(function () {
    Clazz.prepareCallback(this, arguments);
    this.zz = 'zz';
    this.xx0 = null;
    Clazz.instantialize(this, arguments);
  }, test, 'Test_4$1', test.Test_6);
  Clazz.prepareFields(c$, function () {
    this.xx0 = Clazz.newArray( - 1, [
      'x1',
      'x2'
    ]);
      {
        System.out.println(Clazz.castObjectAs('xx0[0]=' + this.xx0[0], 'String'));
      }
  });
  var rc = c$;
  c$ = Clazz.p0p();
  return rc;
};

But, alternatively, I do not understand why there is any preliminary code in the first place. Why not execute the same as Java, just processing all at the same time? Why would this not work, as long as it is executed at the correct time? I think perhaps it is because early on in J2S development the initializing sequence was out of order.

c$.$Test_4$1$ = function () {
  if (Clazz.isClassDefined('test.Test_4$1')) return test.Test_4$1;
  Clazz.pu$h();
  c$ = Clazz.decorateAsClass(function () {
    Clazz.prepareCallback(this, arguments);
    Clazz.instantialize(this, arguments);
  }, test, 'Test_4$1', test.Test_6);
  Clazz.prepareFields(c$, function () {
    this.zz = 'zz';
    this.xx0 = Clazz.newArray( - 1, [
      'x1',
      'x2'
    ]);
      {
        System.out.println(Clazz.castObjectAs('xx0[0]=' + this.xx0[0], 'String'));
      }
  });
  var rc = c$;
  c$ = Clazz.p0p();
  return rc;
};

Bob Hanson

Nested static inner classes wrong field order

public class Test1 {
    public static String s1 = "s1";
    public static class Test2{
        public static String s2 = "s2"+Test1.s1;
    }
}

Will compile into
Clazz.declarePackage("test");
c$ = Clazz.declareType(test, "Test1");
Clazz.pu$h();
c$ = Clazz.declareType(test.Test1, "Test2");
c$.s2 = c$.prototype.s2 = "s2" + test.Test1.s1;
c$ = Clazz.p0p();
Clazz.defineStatics(c$, "s1", "s1");

Try to run Main.main.

public class Main {
    public static void main(final String[] args){
        System.out.println(Test1.s1);
        System.out.println(Test1.Test2.s2);
    }
}

It will show
s1
s2undefined

Expected
s1
s2s1


Original issue reported on code.google.com by [email protected] on 9 Sep 2011 at 10:44

c$ is global

There is no need for c$ to be a global. It can be removed from being a global value by the following process:

  1. changing all Clazz.pu$h() calls to Clazz.pu$h(c$)

  2. in j2slib, changing Clazz.pu$h and Clazz.p0p to:

Clazz.pu$h = function (c$) {
		Clazz.cla$$$tack,push(c$)
};
Clazz.p0p = function () {
		return  Clazz.cla$$$tack,pop();
};

  1. in j2slib, wrapping all JavaScript that contains references to c$ with a localizing function:

     	eval ("(function(){var c$;" + transport.responseText + "})()");
    

Alternatively, better, would be for the compiler to make sure c$ is local.

This completes the localization of all J2S variables in SwingJS. The only global variables in SwingJS are Clazz and the various packages such as java, org, and com.

This works as described for SwingJS.

How to load applet in specific container?

How to load applet in specific container? Where is the docs about SwingJS.getApplet() ?

I see.

Info.useFrame=true
</script>
<div id=testApplet>
 <script>
  SwingJS.getApplet('testApplet', Info)
 </script>
</div>

Generating j2slib.zip from scratch

Hi, I'm trying to figure out how to generate j2slib.zip from scratch - i.e. without reusing files from inside the j2slib.zip already in the git repository. I can regenerate most of it, however there are some differences. I am using the j2s-eclipse-3.8 branch, and I'm using the Makefile in PR #6 to do the build. Roughly, what it does is:

  1. Delete sources/net.sf.j2s.lib/j2slib.zip.
  2. Build the plugin projects:
    1. net.sf.j2s.core
    2. net.sf.j2s.ajax
    3. net.sf.j2s.ui
    4. net.sf.j2s.lib
  3. Install the above to Eclipse
  4. Build the j2s projects:
    1. net.sf.j2s.ajax
    2. net.sf.j2s.java.core
    3. net.sf.j2s.java.org.eclipse.swt
  5. Runs the j2s.pack.lib target in sources/net.sf.j2s.lib/build/build.xml.

The build succeeds, but my j2slib.zip is a bit different. Here are the differences:

Unexplained missing files (not in my j2slib.zip, but in the one in git):

-java/io/FileInputStream.js
-java/io/FileOutputStream.js
-java/lang/Object.js
-java/net/URL.js

Missing, but git grep -- sources suggests that nothing is using them:

-net/sf/j2s/ajax/PipeManager.js
-net/sf/j2s/ajax/PipeObject.js

Missing, but git log -p shows you're no longer building these, so I don't need to either:

-java/error.z.js
-java/lang/reflect.z.js
-net/sf/j2s/ajax/simple.z.js
-org/eclipse/swt/custom/images/**
-org/eclipse/swt/events.z.js
-org/eclipse/swt/more.z.js # moved to widgets
-org/eclipse/swt/layout/FillLayout.z.js
-org/eclipse/swt/layout/GridLayout.z.js
-org/eclipse/swt/widgets/Common.z.js
-org/eclipse/swt/widgets/DesktopListener.js
-org/eclipse/swt/widgets/Menu.z.js
-org/eclipse/swt/widgets/TabFolder.z.js
-org/eclipse/swt/widgets/Tray.z.js

Extra files on my side, probably just a part of the newer version of the source code:

+j2slib.src.z.js
+j2slib.swt.z.js
+net/sf/j2s/ajax/annotation/SimpleComment.js
+net/sf/j2s/ajax/annotation/SimpleIn.js
+net/sf/j2s/ajax/annotation/SimpleInOut.js
+net/sf/j2s/ajax/annotation/SimpleOut.js
+net/sf/j2s/ajax/ISimpleCacheable.js
+net/sf/j2s/ajax/ISimpleCometable.js
+net/sf/j2s/ajax/ISimpleConstant.js
+net/sf/j2s/ajax/ISimpleEnum.js
+net/sf/j2s/ajax/ISimpleGeoLocationBinding.js
+net/sf/j2s/ajax/ISimpleGeoLocation.js
+net/sf/j2s/ajax/ISimplePipePriority.js
+net/sf/j2s/ajax/ISimpleRequestBinding.js
+net/sf/j2s/ajax/ISimpleRequestInfoBinding.js
+net/sf/j2s/ajax/ISimpleRequestInfo.js
+net/sf/j2s/ajax/SimpleClassLoader.js
+net/sf/j2s/ajax/SimpleFactory.js
+net/sf/j2s/ajax/SimpleNamedThreadFactory.js
+net/sf/j2s/ajax/SimplePipeSequence.js
+net/sf/j2s/ajax/SimpleRPCUtils.js
+net/sf/j2s/ajax/SimpleSource4Java.js
+net/sf/j2s/ajax/SimpleSource4ObjectiveC.js
+net/sf/j2s/ajax/SimpleThreadConfig.js
+net/sf/j2s/ajax/SimpleThreadHelper.js
+net/sf/j2s/ajax/SimpleThreadPoolExecutor.js
+net/sf/j2s/ajax/SourceUtils.js
+net/sf/j2s/annotation/J2SDebug.js
+net/sf/j2s/annotation/J2SIgnoreImport.js
+net/sf/j2s/annotation/J2SIgnore.js
+net/sf/j2s/annotation/J2SIngoreSuperConstructor.js
+net/sf/j2s/annotation/J2SKeep.js
+net/sf/j2s/annotation/J2SNative.js
+net/sf/j2s/annotation/J2SNativeSrc.js
+net/sf/j2s/annotation/J2SOptionalImport.js
+net/sf/j2s/annotation/J2SOverride.js
+net/sf/j2s/annotation/J2SPrefix.js
+net/sf/j2s/annotation/J2SRequireImport.js
+net/sf/j2s/annotation/J2SSuffix.js
+net/sf/j2s/store/CookieStore.js
+net/sf/j2s/store/HTML5LocalStorage.js
+net/sf/j2s/store/INIFileStore.js
+net/sf/j2s/store/IStore.js
+net/sf/j2s/store/SimpleStore.js
+net/sf/j2s/store/xss-cookie.html
+net/sf/j2s/store/XSSCookieStore.js
+org/eclipse/swt/dnd.z.js
+org/eclipse/swt/widgets/images/packed.gif
+org/eclipse/swt/widgets/more.z.js

Could you tell me the reason behind these differences, and how I can generate j2slib to exact match the one distributed in git?

Possibility to run this outside of eclipse

Hello Renjian, I'm trying to package Jmol for Debian, but it seems that they require the user to run java2script as an eclipse plugin. This is very hard to automate in a script, so we can't do this. I'm wondering what sort of work would be needed to run java2script outside of eclipse, as a standalone program?

Graphics2d not honouring alpha channel

It looks like rendering with transparency stopped working after 774962a

This is most likely a runtime issue - @benzoid did some careful testing with JalviewJS, stepping through all subsequent commits after 774962a to see what broke (https://issues.jalview.org/browse/JAL-4025?focusedCommentId=25553&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-25553):

774962a - last fully working commit
272041b - rendering of different coloured transparent rectangles on top of each other stops working (ie only see colour for last rendered transparent rectangle).
1f2922e - rendering an image with transparency on top of an existing image stops working (ie only see transparent image).

Cannot convert Boolean object to Primitive value

This issue is present in 2.0.0 but not 3.1.1

When trying to print a Boolean object, the javascript created by j2s crashes because it cannot convert the object to a primitive value.

Code:

package test;

public class BooleanValuePrinting {
    	
	public static void main(String[] args) 
	{
		Boolean b = Boolean.FALSE;
		
		System.out.println("Checking Boolean.FALSE");
		System.out.println(Boolean.FALSE);
		
		System.out.println("Checking Boolean.TRUE");
		System.out.println(Boolean.TRUE);
		
		System.out.println("Checking b");
		System.out.println(b);
		
		System.out.println("done");
	}
}

Regardless of order, the j2s version crashes when trying to print a Boolean.

Boolean.FALSE fails to set Boolean value to false.

This issue is present in both 2.0.0 and 3.1.1

Code:
`
public class Test_Boolean {

public static void main(String[] args) {
    Boolean b = Boolean.FALSE;
    System.out.println(Boolean.FALSE ? "FAILED" : "OK");
    System.out.println(b? "FAILED" : "OK");
}

}
`

This should print OK for both tests but it prints FAILED when run through j2s.

Double.compareTo is not defined

(new Double(3)).compareTo(new Double(4))

fails.

This is necessary for using Double(x) as a key in a Hashtable.

My solution:

Number.prototype.compareTo = function(x) { var a = this.valueOf(), b = x.valueOf(); return (a < b ? -1 : a == b ? 0 : 1) };

NoSuchMethodException: ... JavaModel.flushExternalFileCache(java.lang.Void) when building project using Java2Script builder

Java2Script throw an NoSuchMethodException for the method org.eclipse.jdt.internal.core.JavaModel.flushExternalFileCache(java.lang.Void)

when building a project using the Java2Script Builder.

Steps to reproduce

For a project using the Java2Script Builder create an Ant file and use the internal Ant task “eclipse.incrementalBuild” to trigger an Eclipse build. E.g.

    ...
    <target name="build">
        <eclipse.incrementalBuild project="MyProject" kind="full"/>
    </target>
    ...

Running the build target will then display a stack trace in the console, like this:

[eclipse.incrementalBuild] java.lang.NoSuchMethodException: org.eclipse.jdt.internal.core.JavaModel.flushExternalFileCache(java.lang.Void)
[eclipse.incrementalBuild]  at java.lang.Class.getMethod(Class.java:1786)
[eclipse.incrementalBuild]  at net.sf.j2s.core.builder.JavaBuilder.initializeBuilder(JavaBuilder.java:618)
[eclipse.incrementalBuild]  at net.sf.j2s.core.builder.JavaBuilder.build(JavaBuilder.java:168)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
[eclipse.incrementalBuild]  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300)
[eclipse.incrementalBuild]  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:262)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:402)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.resources.Project$1.run(Project.java:556)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:534)
[eclipse.incrementalBuild]  at org.eclipse.core.internal.resources.Project.build(Project.java:111)
[eclipse.incrementalBuild]  at org.eclipse.core.resources.ant.IncrementalBuild.execute(IncrementalBuild.java:80)
[eclipse.incrementalBuild]  at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
[eclipse.incrementalBuild]  at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
[eclipse.incrementalBuild]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[eclipse.incrementalBuild]  at java.lang.reflect.Method.invoke(Method.java:497)
[eclipse.incrementalBuild]  at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[eclipse.incrementalBuild]  at org.apache.tools.ant.Task.perform(Task.java:348)
[eclipse.incrementalBuild]  at org.apache.tools.ant.Target.execute(Target.java:435)
[eclipse.incrementalBuild]  at org.apache.tools.ant.Target.performTasks(Target.java:456)
[eclipse.incrementalBuild]  at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
[eclipse.incrementalBuild]  at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
[eclipse.incrementalBuild]  at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[eclipse.incrementalBuild]  at org.eclipse.ant.internal.core.ant.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:36)
[eclipse.incrementalBuild]  at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
[eclipse.incrementalBuild]  at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:705)
[eclipse.incrementalBuild]  at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:527)
[eclipse.incrementalBuild]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[eclipse.incrementalBuild]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[eclipse.incrementalBuild]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[eclipse.incrementalBuild]  at java.lang.reflect.Method.invoke(Method.java:497)
[eclipse.incrementalBuild]  at org.eclipse.ant.core.AntRunner.run(AntRunner.java:371)
[eclipse.incrementalBuild]  at org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:269)
[eclipse.incrementalBuild]  at java.lang.Thread.run(Thread.java:745)

'....PackageFragment cannot be cast to org.eclipse.jdt.core.IType' error when running 'net.sf.j2s.test.junit' as Java2Script Unit Test

Steps to reproduce

In Eclipse Package Explorer:

  • Right-Click package 'net.sf.j2s.test.junit'
  • Select 'Run As > Java2Script Unit Test'

A 'Problem occured' dialog appears with the message:

'Launching net.sf.j2s.test.junit' has encountered a problem

An internal error occurred during: "Launching net.sf.j2s.test.junit".
org.eclipse.jdt.internal.core.PackageFragment cannot be cast to org.eclipse.jdt.core.IType

The error log contains this entry:

!MESSAGE An internal error occurred during: "Launching net.sf.j2s.test.junit".
!STACK 0
java.lang.ClassCastException: org.eclipse.jdt.internal.core.PackageFragment cannot be cast to org.eclipse.jdt.core.IType
at net.sf.j2s.ui.launching.J2SLaunchingUtil.launchingJ2SUnit(J2SLaunchingUtil.java:149)
at net.sf.j2s.ui.launching.J2SUnitConfigurationDelegate.launch(J2SUnitConfigurationDelegate.java:21)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

(Running individual test classes works fine)

Nested static inner class problem

Having the java clases

public class Test1 {
    public static String s1;
    public static class Test2{
        public static String s2;
        public static class Test3{
            public static String s3;
        }
    }
}

public class Main {
    public static void main(final String[] args){
        System.out.println(Test1.s1);
        System.out.println(Test1.Test2.s2);
        System.out.println(Test1.Test2.Test3.s3);
    }

}

The equivalent Main.js is


Clazz.declarePackage("test");
Clazz.load(null, "test.Main", ["test.Test1"], function() {
    c$ = Clazz.declareType(test, "Main");
    c$.main = Clazz.defineMethod(c$, "main", function(args) {
        System.out.println(test.Test1.s1);
        System.out.println(test.Test1.Test1.Test2.s2);
        System.out.println(test.Test1.Test1.Test2.Test3.s3);
    }, "~A");
});

test.Test1.Test1.Test2.Test3.s3
should be
test.Test1.Test2.Test3.s3


Original issue reported on code.google.com by [email protected] on 9 Sep 2011 at 8:52

cmdlineApi doesn't work in a completely-headless environment

OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
builded command : Command{-cmd->build
 -path->/build/java2script-2.0.0-3.8+git20150412+ds/tests/net.sf.j2s.test.ajax
 }
Gtk-Message: Failed to load module "gail"
Gtk-Message: Failed to load module "atk-bridge"
Gtk-Message: Failed to load module "gail"
Gtk-Message: Failed to load module "atk-bridge"
Eclipse:
An error has occurred. See the log file
/build/java2script-2.0.0-3.8+git20150412+ds/debian/test-tmp/share/eclipse/.metadata/.log.
debian/rules:42: recipe for target 'override_dh_auto_test' failed
make: *** [override_dh_auto_test] Error 13

Then:

$ cat /build/java2script-2.0.0-3.8+git20150412+ds/debian/test-tmp/share/eclipse/.metadata/.log 
!SESSION 2016-10-26 20:43:32.798 -----------------------------------------------
eclipse.buildId=debbuild
java.version=1.8.0_111
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments:  -application net.sf.j2s.ui.cmdlineApi -cmd build -path /build/java2script-2.0.0-3.8+git20150412+ds/tests/net.sf.j2s.test.ajax
Command-line arguments:  -os linux -ws gtk -arch x86_64 -clean -user /build/java2script-2.0.0-3.8+git20150412+ds/debian/test-tmp/share/eclipse -data /build/java2script-2.0.0-3.8+git20150412+ds/debian/test-tmp/share/eclipse -application net.sf.j2s.ui.cmdlineApi -cmd build -path /build/java2script-2.0.0-3.8+git20150412+ds/tests/net.sf.j2s.test.ajax

!ENTRY org.eclipse.osgi 4 0 2016-10-26 20:43:38.009
!MESSAGE An error occurred while automatically activating bundle org.eclipse.jdt.ui (131).
!STACK 0
org.osgi.framework.BundleException: Exception in org.eclipse.jdt.internal.ui.JavaPlugin.start() of bundle org.eclipse.jdt.ui.
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
    at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
    at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:469)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at net.sf.j2s.ui.cmdline.JDTUtils.importProject(JDTUtils.java:108)
    at net.sf.j2s.ui.cmdline.JDTUtils.newProject(JDTUtils.java:75)
    at net.sf.j2s.ui.cmdline.Application.getProject(Application.java:193)
    at net.sf.j2s.ui.cmdline.Application.doBuild(Application.java:170)
    at net.sf.j2s.ui.cmdline.Application.dispatch(Application.java:108)
    at net.sf.j2s.ui.cmdline.Application.dispatchCommands(Application.java:92)
    at net.sf.j2s.ui.cmdline.Application.doTheJobWith(Application.java:76)
    at net.sf.j2s.ui.cmdline.Application.start(Application.java:52)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:32)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed]
    at org.eclipse.swt.SWT.error(SWT.java:4387)
    at org.eclipse.swt.widgets.Display.createDisplay(Display.java:914)
    at org.eclipse.swt.widgets.Display.create(Display.java:900)
    at org.eclipse.swt.graphics.Device.<init>(Device.java:156)
    at org.eclipse.swt.widgets.Display.<init>(Display.java:498)
    at org.eclipse.swt.widgets.Display.<init>(Display.java:489)
    at org.eclipse.swt.widgets.Display.getDefault(Display.java:1634)
    at org.eclipse.jface.preference.PreferenceConverter.<clinit>(PreferenceConverter.java:81)
    at org.eclipse.jdt.ui.PreferenceConstants.initializeDefaultValues(PreferenceConstants.java:3739)
    at org.eclipse.jdt.internal.ui.JavaUIPreferenceInitializer.initializeDefaultPreferences(JavaUIPreferenceInitializer.java:38)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper$1.run(PreferenceServiceRegistryHelper.java:300)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.runInitializer(PreferenceServiceRegistryHelper.java:303)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.applyRuntimeDefaults(PreferenceServiceRegistryHelper.java:131)
    at org.eclipse.core.internal.preferences.PreferencesService.applyRuntimeDefaults(PreferencesService.java:368)
    at org.eclipse.core.internal.preferences.DefaultPreferences.applyRuntimeDefaults(DefaultPreferences.java:166)
    at org.eclipse.core.internal.preferences.DefaultPreferences.load(DefaultPreferences.java:237)
    at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:410)
    at org.eclipse.core.internal.preferences.EclipsePreferences.internalNode(EclipsePreferences.java:663)
    at org.eclipse.core.internal.preferences.EclipsePreferences.node(EclipsePreferences.java:805)
    at org.eclipse.core.internal.preferences.AbstractScope.getNode(AbstractScope.java:38)
    at org.eclipse.core.runtime.preferences.DefaultScope.getNode(DefaultScope.java:76)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.getDefaultPreferences(ScopedPreferenceStore.java:250)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.getPreferenceNodes(ScopedPreferenceStore.java:285)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.internalGet(ScopedPreferenceStore.java:475)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.getBoolean(ScopedPreferenceStore.java:387)
    at org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferenceCache.install(MembersOrderPreferenceCache.java:61)
    at org.eclipse.jdt.internal.ui.JavaPlugin.ensurePreferenceStoreBackwardsCompatibility(JavaPlugin.java:426)
    at org.eclipse.jdt.internal.ui.JavaPlugin.start(JavaPlugin.java:373)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
    ... 37 more
Root exception:
org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed]
    at org.eclipse.swt.SWT.error(SWT.java:4387)
    at org.eclipse.swt.widgets.Display.createDisplay(Display.java:914)
    at org.eclipse.swt.widgets.Display.create(Display.java:900)
    at org.eclipse.swt.graphics.Device.<init>(Device.java:156)
    at org.eclipse.swt.widgets.Display.<init>(Display.java:498)
    at org.eclipse.swt.widgets.Display.<init>(Display.java:489)
    at org.eclipse.swt.widgets.Display.getDefault(Display.java:1634)
    at org.eclipse.jface.preference.PreferenceConverter.<clinit>(PreferenceConverter.java:81)
    at org.eclipse.jdt.ui.PreferenceConstants.initializeDefaultValues(PreferenceConstants.java:3739)
    at org.eclipse.jdt.internal.ui.JavaUIPreferenceInitializer.initializeDefaultPreferences(JavaUIPreferenceInitializer.java:38)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper$1.run(PreferenceServiceRegistryHelper.java:300)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.runInitializer(PreferenceServiceRegistryHelper.java:303)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.applyRuntimeDefaults(PreferenceServiceRegistryHelper.java:131)
    at org.eclipse.core.internal.preferences.PreferencesService.applyRuntimeDefaults(PreferencesService.java:368)
    at org.eclipse.core.internal.preferences.DefaultPreferences.applyRuntimeDefaults(DefaultPreferences.java:166)
    at org.eclipse.core.internal.preferences.DefaultPreferences.load(DefaultPreferences.java:237)
    at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:410)
    at org.eclipse.core.internal.preferences.EclipsePreferences.internalNode(EclipsePreferences.java:663)
    at org.eclipse.core.internal.preferences.EclipsePreferences.node(EclipsePreferences.java:805)
    at org.eclipse.core.internal.preferences.AbstractScope.getNode(AbstractScope.java:38)
    at org.eclipse.core.runtime.preferences.DefaultScope.getNode(DefaultScope.java:76)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.getDefaultPreferences(ScopedPreferenceStore.java:250)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.getPreferenceNodes(ScopedPreferenceStore.java:285)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.internalGet(ScopedPreferenceStore.java:475)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.getBoolean(ScopedPreferenceStore.java:387)
    at org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferenceCache.install(MembersOrderPreferenceCache.java:61)
    at org.eclipse.jdt.internal.ui.JavaPlugin.ensurePreferenceStoreBackwardsCompatibility(JavaPlugin.java:426)
    at org.eclipse.jdt.internal.ui.JavaPlugin.start(JavaPlugin.java:373)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
    at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
    at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:469)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at net.sf.j2s.ui.cmdline.JDTUtils.importProject(JDTUtils.java:108)
    at net.sf.j2s.ui.cmdline.JDTUtils.newProject(JDTUtils.java:75)
    at net.sf.j2s.ui.cmdline.Application.getProject(Application.java:193)
    at net.sf.j2s.ui.cmdline.Application.doBuild(Application.java:170)
    at net.sf.j2s.ui.cmdline.Application.dispatch(Application.java:108)
    at net.sf.j2s.ui.cmdline.Application.dispatchCommands(Application.java:92)
    at net.sf.j2s.ui.cmdline.Application.doTheJobWith(Application.java:76)
    at net.sf.j2s.ui.cmdline.Application.start(Application.java:52)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:32)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)

I can work around the problem for now by running j2s inside xvfb but it would be nice to avoid loading the graphical stuff completely, since it doesn't need it. Note that Eclipse itself works fine in non-graphical mode, I can run things like org.eclipse.ant.core.antRunner etc, just not net.sf.j2s.ui.cmdlineApi.

"j2slib.z.js" FileNotFoundException when building j2slib the first time

Steps to reproduce

  • go to sources/net.sf.j2s.lib
  • make sure no directory j2slib exists. (run rm -r j2slib if necessary)
  • run ant -f build/build.xml

The build will report these errors for the target j2s.pack.core:

  • [java] java.io.FileNotFoundException: /Users/ub/work/project/sd/thirdparty/java2script(java2script)/sources/net.sf.j2s.lib/build/../../net.sf.j2s.lib/j2slib/j2slib.z.js (No such file or directory)
  • [java] java.io.FileNotFoundException: /Users/ub/work/project/sd/thirdparty/java2script(java2script)/sources/net.sf.j2s.lib/build/../../net.sf.j2s.lib/j2slib/j2slib.src.z.js (No such file or directory)
  • [java] java.io.FileNotFoundException: /Users/ub/work/project/sd/thirdparty/java2script(java2script)/sources/net.sf.j2s.lib/build/../../net.sf.j2s.lib/j2slib/j2slib.swt.z.js (No such file or directory)
  • [java] java.io.FileNotFoundException: /Users/ub/work/project/sd/thirdparty/java2script(java2script)/sources/net.sf.j2s.lib/build/../../net.sf.j2s.lib/j2slib/j2slibcore.z.js (No such file or directory)

(Complete log of initial run)

Workaround

When running ant -f build/build.xml a second time the errors are gone.

(Complete log of second run)

Possible Solution

It looks like the order in the processing needs to be changed. The compacted files are referenced before they are created.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.