jshen
jshen

Reputation: 11907

Setting groovysh classpath from a pom

I have a java project (not using groovy) but I'd like to interactively play with my java classes within groovysh. Is there an easy way to use the pom from my project to set the classpath of groovysh?

Upvotes: 3

Views: 1467

Answers (3)

Tomislav Nakic-Alfirevic
Tomislav Nakic-Alfirevic

Reputation: 10173

Just for the record, I've found a way to do it which I consider much more elegant when the project uses the gmaven-plugin: run mvn groovy:shell and you're ready to issue commands with the same classpath available to groovysh as the one available to the project in question!

Upvotes: 7

Pascal Thivent
Pascal Thivent

Reputation: 570335

MOP might help:

Scripting Goodies

Other times, you just need need the CLASSPATH so you can use it in a manually crafted script your running. Try this.

mop classpath org.apache.camel:camel-example-pojo-messaging

Update: The above command can be used to output the classpath of an existing maven artefact. For example:

$ ./mop classpath org.hibernate:hibernate-core:3.3.2.GA

Prints the following output:

/home/pascal/opt/mop/repository/org/hibernate/hibernate-core/3.3.2.GA/hibernate-core-3.3.2.GA.jar:/home/pascal/opt/mop/repository/antlr/antlr/2.7.6/antlr-2.7.6.jar:/home/pascal/opt/mop/repository/commons-collections/commons-collections/3.1/commons-collections-3.1.jar:/home/pascal/opt/mop/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar:/home/pascal/opt/mop/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar:/home/pascal/opt/mop/repository/javax/transaction/jta/1.1/jta-1.1.jar:/home/pascal/opt/mop/repository/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.jar

That can be used somewhere else. As I said, it might help but I'm not 100% sure it will suit your needs (it seems the artifact needs to be deployed in a remote repo).

Upvotes: 3

armandino
armandino

Reputation: 18528

You can add them to classpath with -cp e.g.

groovysh -cp some.jar:another.jar

Upvotes: 1

Related Questions