1

When I have tried to import a project containing some JavaScript into a Workspace (using the Neon.M6 Version of Eclipse), I get this error:

eclipse.buildId=4.6.0.I20160317-0200
java.version=1.8.0_05
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US

org.eclipse.core.jobs
Error
Wed Mar 30 18:38:50 CEST 2016
An internal error occurred during: "Validating ****".

java.lang.NoClassDefFoundError: jdk/nashorn/internal/runtime/ECMAException
    at org.eclipse.wst.jsdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:860)
    at org.eclipse.wst.jsdt.core.dom.ASTParser.createAST(ASTParser.java:651)
    at org.eclipse.wst.jsdt.internal.core.validation.JavaScriptValidator.validate(JavaScriptValidator.java:62)
    at org.eclipse.wst.validation.Validator$V2.validate(Validator.java:1159)
    at org.eclipse.wst.validation.internal.ValManager.validate(ValManager.java:704)
    at org.eclipse.wst.validation.internal.ValManager$1.visit(ValManager.java:665)
    at org.eclipse.wst.validation.internal.ValManager.accept(ValManager.java:810)
    at org.eclipse.wst.validation.internal.ValManager.validate(ValManager.java:669)
    at org.eclipse.wst.validation.internal.ValBuilderJob$Visitor.visit(ValBuilderJob.java:299)
    at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:120)
    at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:84)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
    at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:129)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:52)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:117)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:105)
    at org.eclipse.wst.validation.internal.ValBuilderJob.fullBuild(ValBuilderJob.java:219)
    at org.eclipse.wst.validation.internal.ValBuilderJob.run(ValBuilderJob.java:178)
    at org.eclipse.wst.validation.internal.ValBuilderJob.runInWorkspace(ValBuilderJob.java:126)
    at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.ClassNotFoundException: jdk.nashorn.internal.runtime.ECMAException cannot be found by org.eclipse.wst.jsdt.core_2.0.0.v201603171403
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:444)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:357)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:349)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 27 more

I am using "Eclipse for Scout Developers" that should contain JSDT by default (this is new with Neon, because of the changes in the Scout Framework for Neon).

Here the Eclipse Installation Details of my current installation (only JSDT plugins):

Eclipse Installation Details

Any idea what this can be?

Jmini
  • 9,189
  • 2
  • 55
  • 77
  • How did you retrieve/download JSDT? The new parser on M6 is using nashorn behind the scenes and something did not go right for your installation. – Gorkem Ercan Mar 30 '16 at 21:04
  • The JSDT Plugin should be installed by default in "Eclipse for Scout Developers" (Neon.M6 Version). It is absolutelly possible that the installation is not correct there (because it is new with Neon), but I am not able to verify it. – Jmini Apr 01 '16 at 03:11

1 Answers1

5

I learnt how Nashorn is hooked in JSDT thanks to a chat with G.Erkan. Here I'm writing down the mechanism. I think this is enough to understand and fix the behavior.

Nashorn is a Javascript runtime library, available from Java 8+ in the <java-home>/lib/ext folder.

An OSGi bundle, by default, uses the boot class loader, which excludes the lib/ext

As JSDT.core is using Nashorn, the JSDT team elaborated a way to load this external lib.

The trick consists in two parts:

At runtime: The org.eclipse.wst.jsdt.nashorn.extension bundle fragment has a class extending the ClassLoaderHook, which extends the bundle classpath by adding the lib/ext folder. To activate the ClassLoaderHook you need to add the following param tot he launch config for the Hook to be effective:

-Dosgi.framework.extensions=org.eclipse.wst.jsdt.nashorn.extension

Practically: you will need to add the parameter to your running configuration or to your product configuration to have it working at a runtime.

For testing at development time, and in local Tycho build: you will need to specify a parameter to tell the Equinox classloader to load the normal Java extension classloader. For this you will need to use the following param:

-Dorg.osgi.framework.bundle.parent=ext

Practically you will need to add the param to your test configuration, and in your tycho configuration. As an example check the webtools.jsdt\tests\pom.xml, where you can see the Tycho surefire param:

<argLine>-Dorg.osgi.framework.bundle.parent=ext</argLine> 

See also

psuzzi
  • 2,187
  • 1
  • 17
  • 21