Grails
  1. Grails
  2. GRAILS-8789

Grails is incorrectly picking up JAVA_HOME varaiable

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: 2.0 final
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Ubuntu 11.10, JDK 1.6 update 31, Grails 2.0.0

      Description

      See the attached screenshots

      My JAVA_HOME variable is pointing to /usr/lib/jvm/java-6-sun

      whereas Grails is picking it up as /usr/lib/jvm/java-6-sun/bin/java

      Steps to reproduce:

      Method 1:

      • Do not install Java via deb packages. Download it manually and move the jdk directoty to /usr/lib/jvm/java-6-sun
      • Use
        export JAVA_HOME=/usr/lib/jvm/java-6-sun
      • Run "grails". It will complain JAVA_HOME is not set

      Method 2:

      • Install Grails via PPA (deb package)
      • Do not install Java via deb packages. Download it manually and move the jdk directoty to /usr/lib/jvm/java-6-sun
      • Now create links using:
        • sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-6-sun/bin/java 1062
          sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java-6-sun/bin/jar 1062
          sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/java-6-sun/bin/javadoc 1062
          sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/java-6-sun/bin/javap 1062
          sudo update-alternatives --install /usr/bin/jarsigner jarsigner /usr/lib/jvm/java-6-sun/bin/jarsigner 1062
          sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-6-sun/bin/javac 1062
          sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/java-6-sun/bin/javah 1062
          sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/java-6-sun/bin/javaws 1062 
          
      • Set a GRAILS_HOME variable in /etc/environment. Please note that it picks up only System wide variables.

        Activity

        Hide
        Raviteja added a comment - - edited

        I'm not sure of the steps to be followed to submit a pull request on github to contribute to grails code but changing the below line in startGrails will solve it.

        Changed from:

        JAVA_HOME=$(update-alternatives --query java | grep Value | sed 's_^Value: __g' | sed 's_/jre/bin/java__g')
        

        to:

        if [ ! $JAVA_HOME ]; then
                JAVA_HOME=$(update-alternatives --query java | grep Value | sed 's_^Value: __g' | sed 's_/jre/bin/java__g')
        fi
        

        or

        if [[ -z $JAVA_HOME ]]; then
                JAVA_HOME=$(update-alternatives --query java | grep Value | sed 's_^Value: __g' | sed 's_/jre/bin/java__g')
        fi
        
        Show
        Raviteja added a comment - - edited I'm not sure of the steps to be followed to submit a pull request on github to contribute to grails code but changing the below line in startGrails will solve it. Changed from: JAVA_HOME=$(update-alternatives --query java | grep Value | sed 's_^Value: __g' | sed 's_/jre/bin/java__g') to: if [ ! $JAVA_HOME ]; then JAVA_HOME=$(update-alternatives --query java | grep Value | sed 's_^Value: __g' | sed 's_/jre/bin/java__g') fi or if [[ -z $JAVA_HOME ]]; then JAVA_HOME=$(update-alternatives --query java | grep Value | sed 's_^Value: __g' | sed 's_/jre/bin/java__g') fi
        Hide
        Raviteja added a comment -
        Show
        Raviteja added a comment - Pull request: https://github.com/marcoVermeulen/grails-ubuntu/pull/1
        Hide
        Marco Vermeulen added a comment - - edited

        Hi Ravi,

        I've had a look at your pull request but don't believe that this is a bug, nor is it necessary to apply this fix. Allow me to explain:

        When you use a PPA, you are tying yourself into the strict use of the Debian/Ubuntu package management system. All my PPA packages internally specify the following dependencies (taken from the packages control file):

        Depends: openjdk-6-jdk | sun-java6-jdk, ${misc:Depends}
        

        This means that if neither of these two packages are installed, it will try pulling down the first one. In other words, you will get the default OpenJDK 6 from the repos. If for whatever reason you want to use the Sun/Oracle JDKs, they are (like my PPA) also available on Launchpad. Please refer here for instructions for installing sun-java6-jdk:
        https://launchpad.net/~ferramroberto/+archive/java

        You could even have both installed, then switch between the two using the official method provided by Debain/Ubuntu, update-alternatives. Just as you would to switch between versions of Grails.

        Of course, if you don't want to use the update-alternatives command to control grails/java, it is just as easy to install it from the zip files provided on the Grails Download page.

        Finally, just to confirm that this is not a bug, I tried installing Grails from the PPA using a fresh install of Ubuntu 11.10, and it worked first time pulling down openjdk-6-jdk as a dependency.

        Hope this helps,
        Regards,
        Marco.

        Show
        Marco Vermeulen added a comment - - edited Hi Ravi, I've had a look at your pull request but don't believe that this is a bug, nor is it necessary to apply this fix. Allow me to explain: When you use a PPA, you are tying yourself into the strict use of the Debian/Ubuntu package management system. All my PPA packages internally specify the following dependencies (taken from the packages control file): Depends: openjdk-6-jdk | sun-java6-jdk, ${misc:Depends} This means that if neither of these two packages are installed, it will try pulling down the first one. In other words, you will get the default OpenJDK 6 from the repos. If for whatever reason you want to use the Sun/Oracle JDKs, they are (like my PPA) also available on Launchpad. Please refer here for instructions for installing sun-java6-jdk: https://launchpad.net/~ferramroberto/+archive/java You could even have both installed, then switch between the two using the official method provided by Debain/Ubuntu, update-alternatives. Just as you would to switch between versions of Grails. Of course, if you don't want to use the update-alternatives command to control grails/java, it is just as easy to install it from the zip files provided on the Grails Download page. Finally, just to confirm that this is not a bug, I tried installing Grails from the PPA using a fresh install of Ubuntu 11.10, and it worked first time pulling down openjdk-6-jdk as a dependency. Hope this helps, Regards, Marco.
        Hide
        Raviteja added a comment -

        Well in that case this can be considered a documentation issue, right?. Personally, I really got confused as to why Grails was not picking up the proper JAVA_HOME variable even it's set.

        Just a note: Oracle will not be officially supporting this PPA and bug fixed versions won't be available quick enough.

        Show
        Raviteja added a comment - Well in that case this can be considered a documentation issue, right?. Personally, I really got confused as to why Grails was not picking up the proper JAVA_HOME variable even it's set. Just a note: Oracle will not be officially supporting this PPA and bug fixed versions won't be available quick enough.
        Hide
        Lari Hotari added a comment -

        This is not a bug in Grails. It's about the grails ubuntu packages:
        https://github.com/marcoVermeulen/grails-ubuntu

        Show
        Lari Hotari added a comment - This is not a bug in Grails. It's about the grails ubuntu packages: https://github.com/marcoVermeulen/grails-ubuntu

          People

          • Assignee:
            Unassigned
            Reporter:
            Raviteja
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development