Results 1 to 4 of 4

Thread: switch Java versions for certain applications (android sdk)

  1. #1
    Join Date
    Sep 2012
    Location
    Maryland, US
    Posts
    623

    Default switch Java versions for certain applications (android sdk)

    I googled around and still found my way here for some help, hopefully someone has the time to help.

    I am trying to compile android project via Android sdk and it complains that it needs Java 1.6 and can not use Java 1.7.

    I have both installed as listed.
    Code:
    ee@linux-r5rj:~/Android/cmsrc> update-alternatives --list java/usr/java/default/bin/java
    /usr/java/latest/bin/java
    /usr/lib/jdk_Oracle/bin/java
    /usr/lib64/jvm/jre-1.6.0-sun/bin/java
    /usr/lib64/jvm/jre-1.7.0-openjdk/bin/java
    lee@linux-r5rj:~/Android/cmsrc>
    Two Questions:

    1) Is there a way to quickly switch between Java versions, for example, while I am running the compiler in Android SDK I could switch to Java 1.6.
    2) Is there a way to run a command and have it and all its helper programs run under Java version 1.6. This would be the "brunch" command in Android sdk.

    There is also the possibility that I am doing something else wrong, so if someone spots some other stupid thing I am doing let me know.
    Kernel: 4.12.14-lp150.12.7-default x86_64 bits:
    64 Desktop: Gnome 3.26.2
    Distro: openSUSE Leap 15.0

  2. #2
    ab NNTP User

    Default Re: switch Java versions for certain applications (android sdk)

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    > I have both installed as listed.
    >
    > Code: -------------------- ee@linux-r5rj:~/Android/cmsrc>
    > update-alternatives --list java/usr/java/default/bin/java
    > /usr/java/latest/bin/java /usr/lib/jdk_Oracle/bin/java
    > /usr/lib64/jvm/jre-1.6.0-sun/bin/java
    > /usr/lib64/jvm/jre-1.7.0-openjdk/bin/java
    > lee@linux-r5rj:~/Android/cmsrc>
    >
    > --------------------


    Good

    > Two Questions:
    >
    > 1) Is there a way to quickly switch between Java versions, for
    > example, while I am running the compiler in Android SDK I could
    > switch to Java 1.6.


    Why switch? Just tell some applications to use one while others use the
    other.

    > 2) Is there a way to run a command and have it and all its helper
    > programs run under Java version 1.6. This would be the "brunch"
    > command in Android sdk.


    I think you're already thinking about this correctly. In my case I run
    about five versions of Eclipse-based things from time to time. Some
    work nicely with the system-maintained Java, and others do not. For all
    of the others I create a startup script (in ~/bin) named whatever I
    want, and all it does is this:

    Code:
    - --------------------
    #!/bin/bash

    cd ~/apps/eclipse-for-sentinel/

    JAVABASE=/usr/java/jdk1.6.0_30/

    export JAVA_BINDIR=${JAVABASE}/bin
    export JAVA_HOME=${JAVABASE}
    export JAVA_ROOT=${JAVABASE}

    ../eclipse

    - --------------------

    Now, as you may have guessed, I have a JDK installed at
    /usr/java/jdk1.6.0_30 and another one at /usr/java/jdk1.7.0 and another
    wherever else. I also have Eclipse (or whatever Java-based app)
    installed, in this case, under ~/apps/WHATEVER where WHATEVER is the
    application-specific directory.

    This script is just for this application and tells Eclipse that the
    JAVA* environment variables are all pointing to a version of Java which
    it likes. Voila... all is well. My system does not need alternatives
    modified, my browsers can keep using whatever plugins they have, and I
    can have as many JDKs/JREs as I want (drive space allowing).

    Good luck.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.19 (GNU/Linux)
    Comment: Using GnuPG with undefined - http://www.enigmail.net/

    iQIcBAEBAgAGBQJQx1OYAAoJEF+XTK08PnB5y1gP/31vrztlQc6bVszbE+np98Rm
    4Ugpa6T50tNvevnhIaoHahRYzNIdX00GzMkXe5/HXmn4EoAOyMsqNRkDuGjw2YMh
    VfC6fzQABuYGfQ358TsbXj/bdRLFvUYIMGxfOzPAPpSnwBLAcmhDjeBzIdAStY3P
    jtCTJtv1uM7mhF2zZVKrRIHz/kr9y2aE1Nwt7Ww4QmwKgnYAQcCQG7uj11PtD2VJ
    rTjgZx4jcF91ckfN3m7x+JyX92u8xq2BzTsct2fJTvXtmE2+P4dDyCW3qdV5rSmD
    OCq55xGBIDB6zDmqHrfp+UPUT07q2owhHz1OVts/SEM7awAXm/aV3+24HthTrUs5
    85MgywzMGaOB7vUUM9/8ZDYuBjLP2HyeSy5XLYmvrhRygGp2rPV7ApoIWAGRqZs/
    LQbSFL2oHxcOUkDujLnb38DfGKlfd1rSZ+YGkEJuh/kLuX91VYllM8F7a+Svo/jO
    joJwkGI3zSDEVS31wL1l2zFniKVsHruU/eAeqd1PhwVgddIamp7uR90U9wLGnqhR
    5lZKALFV83mpsDsWsYsRpdOUzcvqsIKtNTa01Z2MYh9U6Y6mUJ6bshpmd5cO3lMq
    VD7X2prQp3TOThuGfLEzOeahWBt0nqDI6mvtzrDldGt5xH5AWP8c4EzT+fe2Woxa
    QjIVBGEYyA47PCBlRQ6O
    =6FSc
    -----END PGP SIGNATURE-----

  3. #3
    Join Date
    Sep 2012
    Location
    Maryland, US
    Posts
    623

    Default Re: switch Java versions for certain applications (android sdk)

    Code:
    Code:
    - --------------------
    #!/bin/bash
    
    cd ~/apps/eclipse-for-sentinel/
    
    JAVABASE=/usr/java/jdk1.6.0_30/
    
    export JAVA_BINDIR=${JAVABASE}/bin
    export JAVA_HOME=${JAVABASE}
    export JAVA_ROOT=${JAVABASE}
    
    ../eclipse
    Hey Thank you for this, That looks like exactly what I need. I think I will name the scripts eclipsejava16 or something similar.
    Kernel: 4.12.14-lp150.12.7-default x86_64 bits:
    64 Desktop: Gnome 3.26.2
    Distro: openSUSE Leap 15.0

  4. #4
    Join Date
    May 2010
    Location
    Space Colony Lagrange Point 22° à, 77° Ƅ, 56° ɤ, 99° ɜ
    Posts
    3,166

    Default Re: switch Java versions for certain applications (android sdk)

    Quote Originally Posted by anika200 View Post
    Code:
    Code:
    - --------------------
    #!/bin/bash
    
    cd ~/apps/eclipse-for-sentinel/
    
    JAVABASE=/usr/java/jdk1.6.0_30/
    
    export JAVA_BINDIR=${JAVABASE}/bin
    export JAVA_HOME=${JAVABASE}
    export JAVA_ROOT=${JAVABASE}
    
    ../eclipse
    Hey Thank you for this, That looks like exactly what I need. I think I will name the scripts eclipsejava16 or something similar.
    Did you try changing the JRE / JDK in eclipse ? I think eclipse can scan for all available JREs and JDKS on system
    You can also set the the compiler level for each workspace. wrkspc1 may produce 1.5 classes and wrkspc1 may be prodded to produce 1.6 classes
    GNOME Version 3.20.2
    openSUSE Leap 42.3 64-bit

    www.vazhavandan.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •