1

Editing the original question.

I am trying to execute a groovy script which uses classes from an external jar. How can I execute the groovy file from command line?

This is the command I tried

  groovy -cp .:cicdutilities-1.0-SNAPSHOT.jar:http-builder-0.4.0.jar Test_Execution.groovy

and getting the error :

`org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /Users/sroy107/git/CICD-2020/src/main/java/com/groovy/Test_Execution.groovy: 188: unable to resolve class HTTPBuilder @ line 188, column 24. def http = new HTTPBuilder(baseUrl) ^ 1 error`

I was not aware earlier that we need two jars. This command is not working. Could somme one please help me on this.

Sourabh Roy
  • 159
  • 1
  • 18
  • 1
    what is the platform? classpath uses platform aware aware - ";" may be ending the command. It helps if you can add details about "not working " part. – Jayan May 11 '20 at 03:33
  • I am trying to do this on macos.. – Sourabh Roy May 11 '20 at 13:24
  • I am getting this error: groovy sroy107$ groovy -cp .;cicdutilities-1.0-SNAPSHOT.jar Test_Execution.groovy error: neither -e or filename provided – Sourabh Roy May 11 '20 at 13:27
  • as i know on mac paths separated with colon `:` – daggett May 11 '20 at 16:53
  • I am not if adding : resolves my issue one step ahead but this what is happening now: I am executing the below command groovy -cp .:cicdutilities-1.0-SNAPSHOT.jar:http-builder-0.4.0.jar Test_Execution.groovy and getting the error : org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /Users/sroy107/git/CICD-2020/src/main/java/com/groovy/Test_Execution.groovy: 188: unable to resolve class HTTPBuilder @ line 188, column 24. def http = new HTTPBuilder(baseUrl) ^ 1 error – Sourabh Roy May 11 '20 at 20:18
  • @SourabhRoy : please edit your question with all new details. – Jayan May 12 '20 at 11:47
  • offtopic: Once you fix the current issue, consider using gradle/maven – Jayan May 12 '20 at 11:48
  • edited the original question. I am trying to build a docker image thats why I wanted to execute from command line rather than maven – Sourabh Roy May 12 '20 at 14:01
  • I am able to resolve this issue but in a very ugly way: groovy -cp .:cicdutilities-1.0-SNAPSHOT.jar:http-builder-0.7.1.jar:httpclient-4.3.3.jar:httpcore-4.4.13.jar:json-lib-2.4-jdk15.jar:xml-resolver-1.2.jar:commons-collections-3.2.1-1.0.0.jar src/main/java/com/comcast/groovy/Test_Execution.groovy.. I wish i just could have all these jars in one jar – Sourabh Roy May 12 '20 at 21:10
  • 1
    a jar is a zip file with some metadata in META-INF/MANIFET.MF, you can create a single jar merging all the class files in single a jar and editing a MANIFEST by hand or ignoring it, look [here](https://stackoverflow.com/questions/5080220/how-to-combine-two-jar-files) for a hint on how to do it – user1708042 May 21 '20 at 13:31

0 Answers0