groovy
  1. groovy
  2. GROOVY-1067

java.lang.NoClassDefFoundError: groovy/lang/Script

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-JSR-3
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Eclipse 3.0.1 - RCP, Sun JRE 1.4.2_08, Windows XP
    • Number of attachments :
      0

      Description

      I have an Eclipse RCP application built on Eclipse 3.0.1. I get the error mentioned in the subject line when I do the following:

      • Add the groovy-all-*.jar to the project (both the project build path as well as the plugin.xml runtime path)
      • Add the following code to the project (executed via menu item and script is inserted via a dialog box)

      GroovyShell shell = new GroovyShell();

      String groovyScript = text.getText();

      logger.debug("Running script: " + groovyScript);

      try

      { Object value = shell.evaluate(groovyScript); }

      catch (CompilationFailedException e1)

      { e1.printStackTrace(); }

      catch (Throwable t)

      { t.printStackTrace(); }
      • I get the following stacktrace:

      java.lang.NoClassDefFoundError: groovy/lang/Script
      at java.lang.ClassLoader.defineClass0(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
      at groovy.lang.GroovyClassLoader.access$200(GroovyClassLoader.java:83)
      at groovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:541)
      at groovy.lang.GroovyClassLoader$ClassCollector.call(GroovyClassLoader.java:552)
      at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:635)
      at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:850)
      at org.codehaus.groovy.control.CompilationUnit.classgen(CompilationUnit.java:556)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:461)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:271)
      at groovy.lang.GroovyShell.parseClass(GroovyShell.java:536)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:548)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:527)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:505)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:484)
      at us.fl.state.dep.waste.bpss.first.client.interfaces.dialogs.GroovyScriptDialog$1.widgetSelected(GroovyScriptDialog.java:81)
      at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
      at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
      at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
      at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2773)
      at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2432)
      at org.eclipse.jface.window.Window.runEventLoop(Window.java:668)
      at org.eclipse.jface.window.Window.open(Window.java:648)
      at us.fl.state.dep.waste.bpss.first.client.FirstClientWorkbenchAdvisor$47.run(FirstClientWorkbenchAdvisor.java:632)
      at org.eclipse.jface.action.Action.runWithEvent(Action.java:881)
      at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:915)
      at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:866)
      at org.eclipse.jface.action.ActionContributionItem$7.handleEvent(ActionContributionItem.java:785)
      at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
      at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
      at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2773)
      at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2432)
      at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1377)
      at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1348)
      at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:254)
      at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
      at us.fl.state.dep.waste.bpss.first.client.FirstClientApplication.run(FirstClientApplication.java:68)
      at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
      at org.eclipse.core.launcher.Main.run(Main.java:704)
      at org.eclipse.core.launcher.Main.main(Main.java:688)

      I've tried this with beta 6, JSR 01-03, and the latest CVS build which labels itself as 04-SNAPSHOT.

      I've seen mention of this problem in reference to Eclipse RCP in another JIRA issue, but it was reported as resolved. I'm unsure where to go from here, since the bug still happens in my case.

        Activity

        Hide
        Hein Meling added a comment -

        Is this related to the eclipse plugin??

        Second, does the variables 'text' and 'logger' appear in the context in which you are pasting your script? Not that this should matter for the error at hand...

        How exactly, do you try to execute this script? What menu item are you refering to. Any why should it work the way that you are doing things?? To me it seems rather odd.

        Show
        Hein Meling added a comment - Is this related to the eclipse plugin?? Second, does the variables 'text' and 'logger' appear in the context in which you are pasting your script? Not that this should matter for the error at hand... How exactly, do you try to execute this script? What menu item are you refering to. Any why should it work the way that you are doing things?? To me it seems rather odd.
        Hide
        James Tillman added a comment -

        I was able to make this work by changing the classloader. If I replace my original instantiation of the GroovyShell with the following, things begin to work:

        GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());
        GroovyShell shell = new GroovyShell(loader);

        This appears to be related to issues discussed on the Groovy-User mailing list about Eclipse using a different classloader for each plugin, but I'm not sure. In any case, the problem is most definitely with the way Eclipse does classloading, and is fixed by changing the classloader.

        I hope this helps someone else.

        Show
        James Tillman added a comment - I was able to make this work by changing the classloader. If I replace my original instantiation of the GroovyShell with the following, things begin to work: GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader()); GroovyShell shell = new GroovyShell(loader); This appears to be related to issues discussed on the Groovy-User mailing list about Eclipse using a different classloader for each plugin, but I'm not sure. In any case, the problem is most definitely with the way Eclipse does classloading, and is fixed by changing the classloader. I hope this helps someone else.
        Hide
        Scott Hickey added a comment -

        This original example works fine with the latest plugin.

        Show
        Scott Hickey added a comment - This original example works fine with the latest plugin.

          People

          • Assignee:
            Scott Hickey
            Reporter:
            James Tillman
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: