Using external class files within a script.

  • ajaynad

    ajaynad - 2008-07-01

    First of all, let me congratulate you for creating an excellent scripting for eclipse. I love groovy and your plugin rocks! I was thinking of coming up with something similar to that and I find yours. Hats off!! once again.

    I was playing with your plugin and there were some issues I faced. I am elucidating them below,

    *) Static imports dont work. They throw up compilation issues.
    *) I want to access some classes in a jar file. How do I do that ? I tried adding the jar to
    the PATH variable it did not work. How can I solve this situation ?


    • James E. Ervin

      James E. Ervin - 2008-07-01

      First off thanks for giving groovy monkey a look.  Ok I want you to check a couple of things.

      Things to check:
      1. Make sure the you don't have the plugin Eclipse Monkey installed.  This is probably not your problem, but it bears mentioning.
      2. I am not sure static imports are supported.  Check your version of the org.codehaus.groovy plugin and see it matches the version of Groovy that supports that feature.
      3. This one is easy.  Groovy Monkey has an 'Include' metadata keyword.  From there you can add class folders or jars.  The only limitation is that the jar file must be in the workspace.  You can include it in a project in your workspace or externally link it in.  From the groovy monkey editor, just right click and select the 'Include' option and it should work.  Btw, I have unit tests to back this one up.

      Thanks again,

  • François Rey

    François Rey - 2011-03-09

    I'm having issues using external classes even though I used the Include: directive to include the build dir or the jar from a workspace project. It's like the Include directive is broken.
    I finally copied the code I needed inside my gm script and got it working this way. But I shouldn't really.
    I'm on eclipse 3.6.2 on linux 64bit.
    Groovy Monkey 0.6.1
    Groovy-Eclipse Feature 2.1.2.xx-20110307-1500-e36
      which includes org.codehouse.groovy 1.6.7 and 1.7.8
    Maybe some incompatibility with latest groovy or groovy-eclipse plugin?

  • François Rey

    François Rey - 2011-03-10

    Here's how to reproduce my case where Include does not work.
    1. Import the JSAP project in the workspace.
    2. Add the following script:

     * Menu: UseJSAP
     * Script-Path: /GroovyMonkeyScripts/monkey/
     * Kudos: fmjrey
     * License: EPL 1.0
     * Include: /JSAP/build
    import com.martiansoftware.jsap.stringparsers.ColorStringParser

    3. run the script and obserbve failure:

    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
    UseJSAP.groovy: 9: unable to resolve class com.martiansoftware.jsap.stringparsers.ColorStringParser
     @ line 9, column 1.
       import com.martiansoftware.jsap.stringparsers.ColorStringParser
    1 error
        at org.codehaus.groovy.control.ErrorCollector.failIfErrors(
        at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(
        at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(
        at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(
        at org.codehaus.groovy.control.CompilationUnit.compile(
        at groovy.lang.GroovyClassLoader.doParseClass(
        at groovy.lang.GroovyClassLoader.parseClass(
        at groovy.lang.GroovyShell.parseClass(
        at groovy.lang.GroovyShell.parse(
        at groovy.lang.GroovyShell.evaluate(
        at groovy.lang.GroovyShell.evaluate(
        at groovy.lang.GroovyShell.evaluate(
        at org.codehaus.groovy.bsf.GroovyEngine.eval(
        at org.codehaus.groovy.bsf.GroovyEngine.apply(
        at org.apache.bsf.BSFManager$
        at Method)
        at org.apache.bsf.BSFManager.apply(
        at net.sf.groovyMonkey.RunMonkeyScript.runScript(
        at net.sf.groovyMonkey.RunMonkeyScript.runScript(
        at net.sf.groovyMonkey.RunMonkeyScript$
  • François Rey

    François Rey - 2011-03-10

    I solved my problem.
    First, the JSAP project was located outside my workspace. I knew that for "Include:" to work the target should be in a project from the workspace, but I didn't know I had to take this literally: it should be under the workspace directory on the file system, not elsewhere.
    To remove this limitation I looked up the code and managed to remove this limitation.
    The change is limited to the function net.sf.groovyMonkey.lang.MonkeyScript.getIncludes(ScriptMetadata) which should have the following code:

                final IFile ifile = getWorkspace().getRoot().getFile(new Path(include));
                    final URI uri = ifile.getRawLocationURI();
                    final File file = new File( uri );
                    final URL url = file.isDirectory() ? new URL( addSlash( uri.toString() ) ): uri.toURL();
                    includes.add( url );
  • James E. Ervin

    James E. Ervin - 2011-04-27

    Thanks for the heads up, I am sorry I did not reply sooner.  I will look at your patch and see about including it in a new release.

    I have also been wanting better integration with the Eclipse JDT to allow you to just specify an eclipse java project in your workspace as a dependency and then automatically slurp in all its dependencies through its classpath configuration.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks