Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8278639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:05:09+00:00 2026-06-08T09:05:09+00:00

I’m trying to embed groovy into a large Java application. The Java application should

  • 0

I’m trying to embed groovy into a large Java application.

The Java application should load some utility Groovy scripts at startup.

The application should then run other scripts multiple times. There is also a need to enter some code at a GUI and execute it at user request.

The problem I’m facing is this:

I am loading the startup script like this:

GroovyShell gShell = new GroovyShell();
gShell.evaluate(new FileReader("scripts/autoload.groovy"));

Suppose my autoload.groovy contains:

def prnt(m) {
    println("From Groovy: " + m);
}

This works fine. But when I want to run a user command using:

gShell.evaluate("prnt 66");

I get the error:
groovy.lang.MissingMethodException: No signature of method: Script2.prnt() is applicable for argument types: (java.lang.Integer) values: [66]

How can my user script access the methods already loaded?

Note: I have also tried “autoload.prnt 88”, and still get the error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:05:11+00:00Added an answer on June 8, 2026 at 9:05 am

    Each evaluate call is compiled and run as a separate Script, and

    def prnt(m) {
        println("From Groovy: " + m);
    }
    

    defines a method in the Script class generated from autoload.groovy, which is not accessible from the subsequent “calling” script. However, the scripts run by the same GroovyShell share the same binding, so you can store values in the binding from one script and access them in another. Storing a value in the binding is simply a case of assigning the value to an otherwise undeclared variable:

    prnt = { m ->
        println("From Groovy: " + m);
    }
    

    This stores a closure in the binding variable prnt, and you can call the closure from other scripts in the same shell. Note that

    def prnt = { m ->
    

    or

    Closure prnt = { m ->
    

    would not work, because the def or type makes it a local variable declaration (private to this particular script) rather than an assignment to the binding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.