I have a script where a method is annotated with the #Grab annotation
#Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.2' )
everytime i run the script groovy downloads all the required jars from internet, this makes the execution of the script very slow.
Why is it doing this? It has just downloaded all the necessary jars, i see them in .groovy/grapes
Groovy 1.8.4 on Linux
Thanks for the help
I think it's an issue with the http-builder repo itself having dependencies with a version range.
A possible workaround is here
Also, http-builder seems to have a dependency on Groovy [1.5,1.7.99] so no idea what it does when you Grab using Groovy 1.8
Related
I am running GroovyConsole on a mac (to launch I just do groovyConsole from the command line). I am a newbie so not sure how I can import needed libraries (jars). For example suppose my groovy script needs apache commons httpclient.
Do I need to specify the jar names in the command line when I open groovyConsole or should I be using Grapes? If it is the latter, I am not sure, the exact syntax of the Grab command. I tried the below and it didn't work...
#Grapes([
#Grab('org.apache:commons-httpclient:3.1'),
#GrabConfig(systemClassLoader = true)])
import org.apache.commons.httpclient.Credentials
Any help would be much appreciated.
You can either do just
#Grab('org.apache:commons-httpclient:3.1')
Or you can add jars from the menu in the groovy console itself
I have run groovy script for a while from command line. Recently I have started to work with spock/groovy in the eclipse. I have run couple of test using Groovy Console when console was loaded from eclipse. Any way after these activities I have tried to execute groovy from command line and it failed with the following error:
Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-xml is loaded in version 2.4.3 and you are trying to load version 2.4.1
I was using gvm tool to reinstall groovy and set is a primary version but still have the problem. Something was changed from eclipse where my groovy installation gets affected and can not be fixed by by reinstalling.
I have some search done but did not find solution. most solution were mentioning this problem but they were trying to fix this withing eclipse, where in my case I am trying to fix it outside of eclipse. Also will be nice if I be able to prevent this from happening in the future. If somebody have similar experience please share.
Thanks,
Alexander
I know about Groovysh, but I need to know if it is possible to run groovy CLI directly from groovy.jar placed in deployed war servlet (using one command). I can simplify question. Is there possibility to run Groovy CLI like it works, for example, in Clojure?
java -cp clojure-1.4.0.jar clojure.main
And CLI appears in terminal. This is how things look in clojure. I am looking for one line command which will run groovy CLI in terminal (using only groovy library to run it). I was looking for help in javadoc, found classes which should help, but don't know how to run it. :f
http://groovy.codehaus.org/api/groovy/lang/GroovyShell.html
(If someone knows solution which doesn't meet all criterias, also please answer.)
//EDIT
It seems that it needs groovy.jar, commons-cli.jar, antlr.jar, asm-util.jar and jline.jar. So I've added those files in my war file in WEB-INF/lib directory. Maybe it's good solution to make my own jar which role will be to call Groovy CLI from other jars, but now the question is, how ro run jar placed in WEB-INF/lib directory inside deployed war application via command line?
Greets
Seems like groovysh depends on more libs than the embeddable version contains. I managed to do what you want by using the following command:
$ java -classpath '*' org.codehaus.groovy.tools.shell.Main
But the current directory had to be the dir where all the groovy libs are; i.e. $GROOVY_HOME/lib:
$ cd $GROOVY_HOME/lib
$ java -classpath '*' org.codehaus.groovy.tools.shell.Main
Groovy Shell (2.0.6, JVM: 1.6.0_24)
Type 'help' or '\h' for help.
------------------------------------------------------------------------------
groovy:000>
Invoking a groovy script using CLASSPATH prefix as follows works fine:
CLASSPATH=/path/to/classes groovy -e "(new stuff.XMLUtils()).printIt('test string')"
but changing it to use the classpath arg doesn't:
groovy -classpath /path/to/classes -e "(new stuff.XMLUtils()).printIt('test string')"
and gives the error:
script_from_command_line: 1: unable to resolve class stuff.XMLUtils
Can anyone explain why this is? (The stuff.XMLUtils is just some groovy script i've compiled into /path/to/classes
)
I've done some investigation, and using the following groovy script to dump the classloader
def printClassPath(classLoader) {
println "$classLoader"
classLoader.getURLs().each {url->
println "- ${url.toString()}"
}
if (classLoader.parent) {
printClassPath(classLoader.parent)
}
}
printClassPath this.class.classLoader
With the -classpath arg, i see no entry in the classloader for the passed in classpath arg, (in fact, the only directory is the current working dir), e.g.:
groovy.lang.GroovyClassLoader$InnerLoader#4911b910
groovy.lang.GroovyClassLoader#18203c31
sun.misc.Launcher$AppClassLoader#35a16869
- file:/usr/share/java/ant.jar
- ... (removed for brevity)
- file:/home/admin/groovy/
sun.misc.Launcher$ExtClassLoader#77cde100
- file:/usr/java/jdk1.6.0_23/jre/lib/ext/sunjce_provider.jar
- ...
Using the CLASSPATH=... version shows that the PWD entry above is replaced by the value i've set in the variable.
And if I add debug to the groovy shell executable, the difference in the java call is that the -classpath arg version adds no entry to java's classpath entry (which is ultimately why it's giving a class not found error), but the CLASSPATH=... version does add the path.
Is this a bug in groovy?
EDIT: simple failing example
- - - - xu.groovy
package stuff
def printIt(string) { println string }
- - - -
groovyc -d classes xu.groovy
groovy -cp classes -e "(new stuff.xu()).printIt('test')" # fails
CLASSPATH=classes groovy -e "(new stuff.xu()).printIt('test')" # works
If I remove the package and references to stuff the failing example will work fine.
Answering this myself because I found a solution to the problem.
I was using the default groovy packages from yum in fedora, however found many issues (errors starting groovysh etc, unable to find jline package etc), and have wholly moved over to using downloaded versions from codehaus.org, and manually specifying GROOVY_HOME and editing path to invoke the downloaded one instead.
Now all my examples work as expected.
I'm on MSYS/Win32 + groovy 2.2 RC1 and have another twist:
groovy -cp "./*" script.groovy // Works!
but
groovy -cp some.jar script.groovy // ... not
For some reason, none of the above would work out in my case.
That's strange. I just tried to repeat your explained issue but everything seems to work fine (I made tests with Groovy-Version 1.8.6, 1.7.7 and 1.7.0 on my Ubuntu Computer).
So which version do you use and what is your operating system?
In the Groovy Bug Tracker I have found the following bug: Command line option for classpath (--cp/--classpath) is broken on Windows. But this bug just affects old versions of Groovy (1.5.2, 1.5.3 and 1.5.4). So maybe an upgrade of Groovy will help to fix your problem...
PS: Normally I just would comment this, but unfortunately I haven't enough points for doing this :).
I'm trying to run an ant build in linux and I'm getting odd results. I can't seem to get anything to run without specifying each and every library on the classpath, so I systematically added every jar in the "lib" and "ant/dep/lib" locations to the classpath explicitly.
It runs a bit without any issues (it's a setup batch, so in the first phase of the script, it uses a lot of "input" tasks), then I receive the message that org.apache.tools.ant.taskdefs.optional.PropertyFile was not found. Looking around, I discovered it was located in ant-nodeps.jar and I had added it to the class path, but no change.
Complete failure due to missing libraries I can understand, but why would the build partially function if I was sure I was including every library (including ant-nodeps.jar)?
The script file to launch it is as follows:
#!/QOpenSys/usr/bin/bsh
ANT_HOME=dep/ant
PARAMS="-Dant.home=$ANT_HOME -Dsystem.type=as400 -Dis-as400=y"
LIBS="lib/ant-contrib-1.0b3.jar:lib/ant-launcher.jar:lib/ant.jar:lib/catalina-ant.jar:lib/catalina-deployer.jar:lib/commons-net-2.2.jar:lib/el-api.jar:lib/ganymed.jar:lib/jakarta-oro-2.0.8.jar:lib/jasper-el.jar:lib/jasper.jar:lib/jsp-api.jar:lib/log4j-1.2.16.jar:lib/mail.jar"
ANTLIBS="$ANT_HOME/lib/ant-antlr.jar:$ANT_HOME/lib/ant-jai.jar:$ANT_HOME/lib/ant-starteam.jar:$ANT_HOME/lib/ant-apache-bcel.jar:$ANT_HOME/lib/ant-javamail.jar:$ANT_HOME/lib/ant-stylebook.jar:$ANT_HOME/lib/ant-apache-bsf.jar:$ANT_HOME/lib/ant-jdepend.jar:$ANT_HOME/lib/ant-swing.jar:$ANT_HOME/lib/ant-apache-log4j.jar:$ANT_HOME/lib/ant-jmf.jar:$ANT_HOME/lib/ant-testutil.jar:$ANT_HOME/lib/ant-apache-oro.jar:$ANT_HOME/lib/ant-jsch.jar:$ANT_HOME/lib/ant-trax.jar:$ANT_HOME/lib/ant-apache-regexp.jar:$ANT_HOME/lib/ant-junit.jar:$ANT_HOME/lib/ant-weblogic.jar:$ANT_HOME/lib/ant-apache-resolver.jar:$ANT_HOME/lib/ant-launcher.jar:$ANT_HOME/lib/ant.jar:$ANT_HOME/lib/ant-commons-logging.jar:$ANT_HOME/lib/ant-netrexx.jar:$ANT_HOME/lib/xercesImpl.jar:$ANT_HOME/lib/ant-commons-net.jar:$ANT_HOME/lib/ant-nodeps.jar:$ANT_HOME/lib/xml-apis.jar"
java -classpath $LIBS:$ANTLIBS $PARAMS org.apache.tools.ant.launch.Launcher -buildfile install/install.xml
Any help would be appreciated, even if only suggestions for what to try.
EDIT: In light of oers observation, I realized that there are shell scripts for ant afterall (have pity, I'm no expert in linux), so I'm going to attempt to use it to launch ant rather than try to do the same thing myself. I'll let everyone know of my progress and/or if I was able to fix it doing it that way.
I looked into the shellscript on my machine.
There is an additional parameter set:
-Dant.library.dir=\"$ANT_LIB\"
Perhaps this is needed?
ant_exec_command="exec \"$JAVACMD\" $ANT_OPTS
-classpath \"$LOCALCLASSPATH\"
-Dant.home=\"$ANT_HOME\"
-Dant.library.dir=\"$ANT_LIB\" $ant_sys_opts
org.apache.tools.ant.launch.Launcher
$ANT_ARGS
-cp \"$CLASSPATH\"
$ant_exec_args"
Using the ant scripts to launch the setup seemed to do the trick, specifying parameter -lib as lib and -buildfile as install/install.xml.