Using java library in Scriptrunner

Tatyana Lukyanchikova May 20, 2021

Is it possible to install somewhere jar-files to use them in Scriptrunner?

My example: I want to use HTMLUnit in my groovy script so that it'll be possible to write smth like

import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.*;

Or get classes with Grab.

Where should I upload files from that library? Or that's not correct?

 

Thanks for your attention. 

2 answers

0 votes
Garry May February 14, 2024

Probably a bit late now but I'll add this here for anyone else that's looking!
This should run straight out of the Groovy console in Jira/Confluence etc

//
// How to load and use an external library/dependency in ScriptRunner
//

// Faker       : https://github.com/DiUS/java-faker
// Its library : http://dius.github.io/java-faker/apidocs/index.html
// Declarations: https://mvnrepository.com/artifact/com.github.javafaker/javafaker/1.0.2
//
// Other       : http://docs.groovy-lang.org/latest/html/documentation/grape.html
//
// https://mvnrepository.com/artifact/com.github.javafaker/javafaker

@Grapes(

    @Grab(group='com.github.javafaker', module='javafaker', version='1.0.2')

)

import com.github.javafaker.Faker

Faker fkr = new Faker(new Locale("en.AU"))

return "<p>" + fkr.chuckNorris.fact() + "</p>" + 
"<p>Lorem: " + fkr.lorem().paragraph() + "</p>" + 
"<p>HitchHikers: " + fkr.hitchhikersGuideToTheGalaxy().marvinQuote() + "</p>" + 
"<p>Back to the Future: " + fkr.backToTheFuture().quote() + "</p>"

 

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 20, 2021

Hi @Tatyana Lukyanchikova , yeah I'm using @Grab. If the dependency is not downloaded automatically, you need to install it under maven dependencies on your Server. Usually (~/.m2) folder.

You can use mvn install:install-file command (https://intellipaat.com/community/6786/how-to-add-local-jar-files-to-a-maven-project).

I'm using following code and it works smoothly:)

@Grab('com.xlson.groovycsv:groovycsv:1.3')
import static com.xlson.groovycsv.CsvParser.parseCsv

Suggest an answer

Log in or Sign up to answer