5

I'm working on a project where I'd like users to experiment with Java classes on Groovysh. I'd like to make it convenient for them and want to import certain packages by default, when groovysh starts up so that users would not have to re-type the same imports every time they start the shell. Does anyone know how to accomplish this?

Thanks in advance, igor

ipolevoy
  • 5,432
  • 2
  • 31
  • 46

2 Answers2

4

You can add the imports to $HOME/.groovy/groovysh.rc

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • 3
    Matthew, thanks, this works, but it requires some configuration on the client box. A more convenient way for me would be a command line option to tell groovysh to load a groovy file. Is this possible? This seems a simple task, but I can't see this in documentation. thanks, igor – ipolevoy Jun 15 '10 at 04:20
  • Could you change the script to add the relevant configuration to `groovysh.rc` if it doesn't already exist? – Dónal Jun 15 '10 at 08:06
  • hm, this is an idea, but where can I configure to run a script other than the groovysh.rc? – ipolevoy Jun 15 '10 at 20:35
2

From http://groovy.codehaus.org/Groovy+Shell:

This script, if it exists, is loaded when the shell starts up:

$HOME/.groovy/groovysh.profile

This script, if it exists, is loaded when the shell enters interactive mode:

$HOME/.groovy/groovysh.rc

Edit-line history is stored in this file:

$HOME/.groovy/groovysh.history
gavenkoa
  • 45,285
  • 19
  • 251
  • 303