Results 1 to 5 of 5

Thread: Using multiple Java Versions

  1. #1

    Default Using multiple Java Versions

    Hello all,

    I'm wondering if someone could tell me how to go about setting up OpenSuSE to use multiple versions of Java? I'd like to use these multiple versions in Eclipse, and right now I can only get it to work with Java 1.8, which is my default. Attempting to run with Java 1.6 selected gives me the following error:

    Code:
    Error occurred during initialization of VM
    java/lang/NoClassDefFoundError: java/lang/Object
    I've got this placed in my .bashrc file:

    Code:
    JAVA_HOME=/usr/java/latest
    export PATH=$JAVA_HOME/bin:$PATH
    
    JRE_HOME=/usr/java/latest
    export PATH=$JRE_HOME/bin:$PATH
    How do I also add a path like /usr/java/jdk1.6.0_45, but still also keep /usr/java/latest available?

    Thanks a lot!

  2. #2
    Join Date
    Jun 2008
    Posts
    1,825
    Blog Entries
    1

    Default Re: Using multiple Java Versions

    Quote Originally Posted by oapeter View Post
    Hello all,

    I'm wondering if someone could tell me how to go about setting up OpenSuSE to use multiple versions of Java? I'd like to use these multiple versions in Eclipse, and right now I can only get it to work with Java 1.8, which is my default. Attempting to run with Java 1.6 selected gives me the following error:

    Code:
    Error occurred during initialization of VM
    java/lang/NoClassDefFoundError: java/lang/Object
    I've got this placed in my .bashrc file:

    Code:
    JAVA_HOME=/usr/java/latest
    export PATH=$JAVA_HOME/bin:$PATH
    
    JRE_HOME=/usr/java/latest
    export PATH=$JRE_HOME/bin:$PATH
    How do I also add a path like /usr/java/jdk1.6.0_45, but still also keep /usr/java/latest available?

    Thanks a lot!
    According to the directions from java, they say to delete the old version. In other words, according to java documentation, it's not possible. Now, having said that, I don't believe in can't or "it's impossible". I'm sure there is a way, but I don't know how. See, in each java package the plugin is named the same thing, like fooplugin.so. This is where you'd run into the problem. How to have two of the exact same file name in the same directory is not possible. You'd have to name one of them something else which would then not be recognized by your browser. As far as other apps like eclipse, it might be possible, but then again, you might run into the same problem.
    ______________________________________________________________________________________
    Don't ask "if" something can be done, for it can always be done. Rather instead ask "How" can it be done.

  3. #3
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    12,055
    Blog Entries
    2

    Default Re: Using multiple Java Versions

    Been awhile since I'd set this up...

    IIRC and assuming that nothing has changed in Eclipse the past few variations,
    - You don't need to "properly" install Java in a machine to use in Eclipse. If you look at the Eclipse advanced settings, you will see a section devoted to Java and all you need to do is configure those paths to point to the Java you want. Re-configuration if this section is required regardless how Java exists on the system.

    Now, as for multiple Java on the same machine...
    Several distros use the update-alternatives subsystem, and openSUSE was one of the first to do so. When you configure Java as an update-alternatives option, it's easy to switch from one Java to another.

    So, here are a few links to get you started...
    The official guide (SDB) how to install the Oracle JDK (and less importantly the JRE) on openSUSE
    https://en.opensuse.org/SDB:Installing_Java

    Note that the SDB only describes installing Oracle Java 7, I've taken a deep look at the procedure and it won't work for Oracle 8. Unless and until someone is willing to do the work (or work with me on doing so) I don't know when the SDB will be updated to support Oracle 8. If you do decide to install Oracle 7, I strongly recommend you look at the discussion to the SDB
    https://en.opensuse.org/SDB_Talk:Installing_Java

    And even consider simply running the 3 scripts I created that IMO vastly improve on the basic stuff the SDB describes. Instead of a half hour or longer, you'll have Oracle 7 installed in about 15 seconds (after downloading the Oracle package)
    https://github.com/putztzu/openSUSE_Oracle_Java_Install

    If anyone is interested in seeing how it's possible to maintain separate Java implementations, you can inspect either the guts of the SDB or my scripts, they describe how the actual files are kept separate but sym-linked to the library location all apps expect to find Java.

    For those who may have only a passing interest why this is important, it's because only Oracle Java can provide a fully functional Java compiler. If you're not a developer and only need the JRE, then "any" non-Oracle Java is sufficient and is why openJDK is distributed as only a JRE (despite its name). You can build an openJDK Java compiler, but the packages you build won't run on all Java.

    For the time being, If you must run Oracle 8 and not Oracle 7, I recommend using virtualization to run your Oracle 8 Dev environment in its own configuration. When the Oracle 8 install on openSUSE install is worked out, then an update-alternatives configuration can be created and then you'll be able to run multiple Java on the same machine.

    TSU

  4. #4
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    12,055
    Blog Entries
    2

    Default Re: Using multiple Java Versions

    Quote Originally Posted by oapeter View Post
    Hello all,

    I'm wondering if someone could tell me how to go about setting up OpenSuSE to use multiple versions of Java? I'd like to use these multiple versions in Eclipse, and right now I can only get it to work with Java 1.8, which is my default. Attempting to run with Java 1.6 selected gives me the following error:

    Code:
    Error occurred during initialization of VM
    java/lang/NoClassDefFoundError: java/lang/Object
    I've got this placed in my .bashrc file:

    Code:
    JAVA_HOME=/usr/java/latest
    export PATH=$JAVA_HOME/bin:$PATH
    
    JRE_HOME=/usr/java/latest
    export PATH=$JRE_HOME/bin:$PATH
    How do I also add a path like /usr/java/jdk1.6.0_45, but still also keep /usr/java/latest available?

    Thanks a lot!
    Just a FYI

    Awhile back I was running some Dev that <required> placing a number of settings in the Bash rc (or similar) so in that case I put my Java settings there as well, After all, if I <had> to edit a file to enable/disable <some> settings, why not place all related settings in one place?

    So, first...
    For this situation I highly recommend implementing the environment settings in /etc/profile.local instead of bashrc. If you're the only person using your machine there will be no difference, and settings are easier to manage. Note that if you open /etc/profile directly, it will instruct you not to edit that file or your settings will be lost if an update/upgrade replaces that file. An alternative is to create a config file in the <directory> /etc/profile.d/

    Now, it's simplicity enabling/disabling configs, simply list them in blocks and enable/disable by commenting out unused lines with a hash.

    After changing settings in whatever profile file you're using, you can enable the new settings without rebooting with
    Code:
    source /etc/profile
    TSU

  5. #5

    Default Re: Using multiple Java Versions

    Thanks for the replies!

    I think what I've been doing is pointing Eclipse to the 1.6 directory, but for whatever reason, it can't initialize the VM to run it in. I've been adding the Java versions under Preferences > Java > Installed JRE's.

    I guess if i don't need to actually "install" the additional java versions, then I need to ask somewhere more specific to eclipse.

    Thanks again!

    EDIT: Turns out I made a silly mistake. I downloaded the .rpm and then must have unpacked it like it was a .zip. I downloaded the .tar.gz version and unpacked it, and it works perfectly.

    Sorry!

Posting Permissions

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