GVM/Grails shell script bug?
Asked Answered
A

3

6

I'm on Ubuntu (14.04) and just installed the latest version of GVM (1.3.13). I then used it to install Grails (2.3.7), Groovy (2.2.2) and Gradle (1.11).

Groovy and Gradle seem to have installed perfectly fine (I can execute their SDK commands, such as groovyc, etc.). But whenever I execute any Grails command, from any directory, my entire terminal's screen clears, pauses for a second, and then re-draws my command line prompt. The command never gets executed. Several months ago, on Nabble, another user reported a very similar issue.

From the shell, if I execute echo $GRAILS_HOME, I get:

/home/myuser/.gvm/grails/current

If I ececute echo $PATH I do see that /home/myuser/.gvm/grails/current/bin is on my system path.

So then I decided to dig deeper and actually go to $GRAILS_HOME. It's a symbolic link actually pointing to /home/myuser/.gvm/grails/2.3.7. So when I go there, I see a normal Grails installation, including a bin directory. When I drop into that bin dir, I see:

grails-debug
grails.bat
grails-debug.bat
startGrails.bat
startGrails
grails

I open grails (a shell script) and see:

#!/bin/sh
trap "reset" EXIT
trap "reset" INT
trap "reset" TERM

DIRNAME=`dirname "$0"`
. "$DIRNAME/startGrails"

startGrails org.codehaus.groovy.grails.cli.GrailsScriptRunner "$@"

I modified this as follows:

#!/bin/sh
trap "reset" EXIT
trap "reset" INT
trap "reset" TERM

echo "1..."
sleep 2s

DIRNAME=`dirname "$0"`

echo "2...dirname is $DIRNAME"
sleep 8s

. "$DIRNAME/startGrails"

echo "3..."
sleep 2s

startGrails org.codehaus.groovy.grails.cli.GrailsScriptRunner "$@"

And then saved/exited and ran grails help from the shell. Here was my output:

1...
2...dirname is /home/zharvey/.gvm/grails/current/bin

The last line of output ("2...dirname is...") pauses for 2 seconds, and then my screen clears (as if I had issued a clear command) and my prompt re-appears. At no point in time does my actual command (grails help) actually execute or generate output. So it seems that the exact line where the bug exists is:

. "$DIRNAME/startGrails"

What is this line even doing, and why would it cause the script to fail?

My questions

  • Can someone confirm that this is in fact a Grails or GVM bug, and not a situation where I have installed something incorrectly?
  • Most importantly, can someone tell me what I can do to fix this and get Grails up and running as fast as possible?
Approve answered 22/4, 2014 at 14:6 Comment(2)
Did you '...open a new terminal, or run the following in the existing one: source "${GVM_DIR}/bin/gvm-init.sh"' at the end of installing gvm (as it prints when installation is complete)?Weikert
Thanks @Weikert (+1) - no I didn't (originally). I just did that now, but it didn't change anything. Same functionality as described above still.Approve
K
4

I had a similar problem and my problem was that I had set the JAVA_HOME variable incorrectly. Although JAVA did work on my machine but was set like :

JAVA_HOME=/usr/lib/jvm/jdk1.8.0/bin
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
export PATH

Clearly, when I looked at it more closely, I found out my mistake and set the above as:

JAVA_HOME=/usr/lib/jvm/jdk1.8.0
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

Just a subtle difference, but it did work correctly now and the command

grails

did not fail silently as explained above.

Hope it helps !!

Kalasky answered 18/8, 2014 at 9:24 Comment(0)
A
3

I figured this out with a bit of (very painful) debugging.

In GRAILS_HOME/bin/startGrails (a POSIX script) there is a line that checks to see if JAVA_HOME is set correctly.

I did not install my JDK the recommended way. I don't like using apt-get to configure Java for me. I like to download the JDK myself and add JAVA_HOME to the PATH myself. This was the root of the problem.

Since JAVA_HOME wasn't set up correctly on my Ubuntu machine (because I chose the manual/discouraged approach over the apt-get method), the startGrails script was failing (silently mind you, c'mon Grails team...) because it couldn't access JAVA_HOME:

if [ -z "$JAVA_HOME" ] ; then
    die "JAVA_HOME environment variable is not set"

So I just changed this to:

if [ -z "$JAVA_HOME" ] ; then
    export JAVA_HOME="<value of my $JAVA_HOME var as defined in ~/.bashrc>"

I'm going to leave this up since I'm clearly not the only person encountering this.

Approve answered 22/4, 2014 at 22:58 Comment(0)
C
0

Faced same problem. My solution was to sudo update-alternatives --install /usr/bin/startGrails startGrails /opt/grails-2.4.3/bin/startGrails 2

Confusion answered 15/10, 2014 at 9:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.