Install Groovy

I recently downloaded Groovy -2.3.6 and tried to install it on a Linux system. I am following the instructions from http://groovy-lang.org/install.html . I have set the GROOVY_HOME variable.

export GROOVY_HOME=/home/work/Software/groovy-2.3.6

      

Then I set my environment path variable to Groovy bin folder

  export PATH=$PATH:/home/work/Software/groovy-2.3.6/bin

      

The JAVA_HOME variable has already been created.

Now when I try to execute any Groovy command it generates the 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 this problem. I find that if I set the wrong path to GROOVY_HOME then this can happen. I can't figure out what the correct path for this variable should be. Can anyone help me with this please. Thanks to

+3


source to share


7 replies


The easiest way to install Groovy on Linux / Mac is SDKMAN . Here's what I suggest:

  • undo everything you've already done.
  • install SDKMAN by running curl -s "https://get.sdkman.io" | bash

  • open a new terminal and install Groovy using the command sdk install groovy 2.3.6



Go ahead and use SDKMAN to switch between different Groovy versions (and Gradle, Grails, Griffon, etc.), install new versions, uninstall old versions, etc.

+10


source


While I agree that the GVM solution is most likely the right way to go, I believe that the specific problem you were experiencing was an extension of an error that prevents you from taking place in the install path (and the GROOVY_HOME variable); You also cannot have hyphens or periods in the path.

So, you need something like:



export GROOVY_HOME=/home/work/Software/groovy236

      

This template also contains Windows.

+1


source


On Windows ::

  • Download the latest groovy from http://groovy.codehaus.org/Download
  • unpack tar file (e.g. c: \ groovy)
  • set environment variables: a] GROOVY_HOME to your groovy directory (eg C: \ groovy \ groovy-2.4.6). b] JAVA_HOME to JRE

  • Make sure both GROOVY_HOME / bin and JAVA_HOME / bin are available in your PATH

You can now successfully run your groovy code (e.g. groovy hello.groovy)

+1


source


I had this same problem lately while using groovy -2.0.8. I'm not sure if my groovy -2.0.8 binary was corrupted or if version 2 introduced something fundamentally different, but when I installed groovy -1.8.9 on my path, I no longer got an error when trying to run a groovy script ...

I also found the answer above, stating that you cannot have "hyphens or periods" as misleading and incorrect.

0


source


Try changing your path by removing "\ bin" I got rid of that and it worked great for me.

0


source


The distributions based on Ubuntu (you seem to be using something-y the unix), sudo apt install groovy

.

0


source


I had the same error message and found after a lot of trial and error, the variable GROOVY_HOME

was not set correctly.

The application groovy

relies on a path GROOVY_HOME

pointing to the correct directory, otherwise you will see the error above.

I see the answer above which recommends removing periods from the directory name and adding it to the path. This will work, but can be done in a cleaner way using a symbolic link.

Follow the link below or follow my summary:

https://www.packtpub.com/mapt/book/All%20Books/9781849519366/1/ch01lvl1sec11/Installing+Groovy+on+Linux+and+OS+X

  • Create a named symbolic link current

    that points to the main groovy directory (for example /usr/share/groovy/groovy-2.1.6

    ). The symlink can be located in the same directory that contains the groovy -xyz directory. This approach has the advantage of stripping invalid characters in PATH

    , and can be redirected to a newer version of groovy after an upgrade. Here's an example assuming groovy is installed /usr/share/groovy/

    and groovy is version 2.1.6.

    sudo ln -s /usr/share/groovy/groovy-2.1.6 current

  • Use the new symlink to define a variable GROOVY_HOME

    in your login script (for example .profile

    ):

    export GROOVY_HOME=/usr/share/groovy/current

  • Add GROOVY_HOME/bin

    to variable PATH

    in login script:

    export PATH=$GROOVY_HOME/bin:$PATH

  • NOTE. Your best bet is to log out and log back in before testing, to ensure that the initialization script correctly sets the environment variables

    Check by running groovy -v

I hope this works well for anyone stumbling across this link.

0


source







All Articles