How do you use a custom class in a console script?

I tested using a custom class following the sample script and class included in the ScriptRunner documentation, https://scriptrunner.adaptavist.com/latest/jira/#_script_roots, and it worked correctly in the Script Console specifying the script file. On the server the script file (foo.groovy) is placed in this directory, <jira-home>\scripts. The class file (Bollo.groovy) was placed in <jira-home>\scripts\util. I even tested changing the class directory (e.g. custom). This required changing the corresponding import call in the script (e.g. change 'import util.Bollo' to 'import custom.Bollo') and changing the package declaration in the class file (e.g. change 'package util' to 'package custom'). When I tested the script in the Script Console specifying the script file it worked. However, when I tried to paste the script from the file into the Script Console I get 'unable to resolve class' error when I click run. It appears that ScriptRunner console script is run so that the relative path location does not work like it does for the script file. I am trying to find some information on how to address the script root location in the ScriptRunner console script or where the class needs to be placed to be accessible to the ScriptRunner console script. It appears that the JIRA classes are stored in C:\Program Files\Atlassian\JIRA\atlassian-jira\WEB-INF\classes\com. However, adding a sub-directory to this location with the custom class does not make the class accessible. Can anyone help me to get my class working with a console script?  I am sure there is a simple solution but I cannot find it.  Thank you for any help.

System Info:

JIRA - v6.3.15

ScriptRunner - 3.1.3

 

Files:

foo.groovy

import util.Bollo

log.debug ("Hello from the script")

Bollo.sayHello()

 

Bollo.groovy

package util

public class Bollo {

                public static String sayHello() {

                                "hello sailor!!!"

                }

}

2 answers

1 accepted

Hi Will,

I am afraid is not possible to import a class that exists in a file, in a script that exists in your Script runner console. I think this link https://jamieechlin.atlassian.net/browse/GRV-544 (especially the comments) will help you understand more.

Regards

Thanos 

What I did was create a scratch file (I called it scratch.groovy) and I simply use that for testing all my code instead of the console... and then run it as a file.   I created a simple PHP interface to edit the code, upload new code and run it via a REST call.   using this method I didn't have to worry about where I could us basescript vs. my own class.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

179 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you