views:

103

answers:

3

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?

A: 

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

groovysh -cp some.jar:another.jar
armandino
+2  A: 

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).

Pascal Thivent
how would I get it to dump me into groovysh with a pom's dependencies resolved? I clicked on the documentation link on the site and it said "TODO" :/
jshen
@jshen I've added an example
Pascal Thivent
Quite a nice find!
Tomislav Nakic-Alfirevic
+3  A: 

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!

Tomislav Nakic-Alfirevic