Reputation: 2972
Recently I downloaded Groovy-2.3.6 and try to install it on Linux system. I follow the instruction from http://groovy-lang.org/install.html. I set my GROOVY_HOME variable.
export GROOVY_HOME=/home/work/Software/groovy-2.3.6
Then I set my environment path variable to the Groovy bin folder
export PATH=$PATH:/home/work/Software/groovy-2.3.6/bin
The JAVA_HOME variable is already created.
Now when I'm trying to run any command of Groovy, It generate following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groo/tool/GroovyStarter
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.codehaus.groovy.tools.GroovyStarter. Program will exit.
I was going through some website to solve that problem. I find that if I set wrong path to GROOVY_HOME then it can happen. I can't figure out what should be the right path for that variable. Can anyone help me with this please. Thanks
Upvotes: 8
Views: 32570
Reputation: 1
all commands below failed:
export GROOVY_HOME='/Library/groovy4012'
export PATH=$PATH:/Library/groovy4012/bin
groovy
groovy -v
export PATH=$PATH:/Library/groovy4012/
groovy -v
export PATH=$PATH:/Library/groovy4012
groovy -v
export PATH=$GROOVY_HOME/bin:$PATH
groovy -v
but after this, I tried a different approach
cd /Library/groovy4012/bin
./groovysh
and worked :)
btw it's funny that nobody can explain how the manual installation on Linux/MacOS should be done properly
Upvotes: 0
Reputation: 1017
I met the same problem in windows os. I finally found this page and thanks to the author I solved my problem. In short, don't set GROOVY_HOME
env var. Use something else e.g. GROOVY_DIR
and then set %GROOVY_DIR%\bin
in PATH
. Boom! Groovy is working now.
Upvotes: 0
Reputation: 1877
I had the same error message and found out after much trial and error, the GROOVY_HOME
variable was not set correctly.
The groovy
application relies on the GROOVY_HOME
path pointing to the correct directory, or else you will see the error above.
I see an answer above that recommends removing periods from the directory name and adding it to the path. This will work but could be done in a cleaner way using a symlink.
Follow the link below or follow my summary:
Create a symlink named current
that points to the main groovy directory (e.g. /usr/share/groovy/groovy-2.1.6
). The symlink could be located in the same directory that holds the groovy-x.y.z directory. This approach has the advantages of avoiding invalid characters in PATH
and it can be redirected to a new version of groovy after an upgrade. Here is an example that assumes groovy is installed in /usr/share/groovy/
and groovy version 2.1.6.
sudo ln -s /usr/share/groovy/groovy-2.1.6 current
Use the new symlink to define the GROOVY_HOME
variable in the login script (e.g. .profile
):
export GROOVY_HOME=/usr/share/groovy/current
Add GROOVY_HOME/bin
to the PATH
variable in the login script:
export PATH=$GROOVY_HOME/bin:$PATH
NOTE: It's best to log out and log in before testing to ensure the initialization script sets the environment variables properly
Test by executing groovy -v
I hope this works well for whomever stumbles upon this link.
Upvotes: 0
Reputation: 414
On Ubuntu-based distros (you appear to be using something unix-y), sudo apt install groovy
.
Upvotes: 0
Reputation: 187369
The simplest way to install Groovy on Linux/Mac is with SDKMAN. Here's what I suggest:
curl -s "https://get.sdkman.io" | bash
sdk install groovy 2.3.6
Going forward you can use SDKMAN to switch between different versions of Groovy (and Gradle, Grails, Griffon, etc.), install new versions, remove old versions, and so on.
Upvotes: 23
Reputation: 101
Try changing your path by deleting the "\bin" i got rid of that and it worked perfectly for me.
Upvotes: 0
Reputation: 7849
On Windows ::
set environment variables: a] GROOVY_HOME to your groovy directory(for e.g C:\groovy\groovy-2.4.6). b] JAVA_HOME to JRE
Make sure that both GROOVY_HOME/bin and JAVA_HOME/bin are available in your PATH
Now you can run your groovy code successfully (for e.g groovy hello.groovy)
Upvotes: 1
Reputation: 49
I had this same issue recently when using groovy-2.0.8. I'm not sure whether my groovy-2.0.8 binary was corrupt or whether version 2 introduced something fundamentally different but, when I set groovy-1.8.9 to my path I no longer got the error when attempting to run a groovy script.
I also found the answer above stating that you cannot have "hyphens or periods" as misleading and incorrect.
Upvotes: 0
Reputation: 1720
Although I agree the GVM solution is likely the correct way to go, I believe the specific issue you were running into was an extension of the bug that prevents you from having a space in the install path (and the GROOVY_HOME variable); You also can't have hyphens or periods in the path.
So, you would need something like:
export GROOVY_HOME=/home/work/Software/groovy236
This pattern holds true Windows as well.
Upvotes: 2