Page 1 of 9 123 ... LastLast
Results 1 to 10 of 90

Thread: Installing and setting up Eclipse with Sun's Java

  1. #1
    Join Date
    Jul 2005
    Beans
    1,535
    Distro
    Ubuntu 8.04 Hardy Heron

    Installing and setting up Eclipse with Sun's Java

    This howto explains how to install Eclipse and Sun's Java on Ubuntu 8.04 (Hardy Heron), and how to make Eclipse actually use Sun's Java solving the "Eclipse is horribly slow" problem caused by bug 45347.

    The entire install process consists simply of installing the following 2 meta packages: eclipse and sun-java6-jdk. Note, you can optionally choose to use the openjdk-6-jdk package instead of Sun's package, which is the open-source jdk for ubuntu.
    Code:
    sudo apt-get install eclipse sun-java6-jdk
    This will install the required packages, however, Eclipse will run very slowly since it will be using GNU's java, not Sun's (or optionally openjdk). To make Sun's java the default on the system, use the update-java-alternatives command:

    Code:
     sudo update-java-alternatives -s java-6-sun
    Next, edit the JVM configuration file
    Code:
    sudo -b gedit /etc/jvm
    and add the following to the top of the file
    Code:
    /usr/lib/jvm/java-6-sun
    There is a bug right now were Eclipse ignores Ubuntu's java-common settings and uses its own (bug 45347). To work around the bug, you need to edit Eclipse's java_home file
    Code:
    sudo -b gedit /etc/eclipse/java_home
    and add
    Code:
    /usr/lib/jvm/java-6-sun
    to the top of the file.

    Lastly, if you have lots of memory you may want to increase the heap size (warning: If you make the heap size too large then parts of eclipse will continuously swap in and out.).
    The settings can be altered by editing the eclipse.ini file.
    Code:
    sudo -b gedit /usr/lib/eclipse/eclipse.ini
    The argument Xms refers to the minimum heap size and Xmx refers to the maximum heap size.
    For more on tuning the Eclipse JVM heap size, you can refer to this IBM article.

    That's it.

    Edit 1: Make mention of the /usr/share/eclipse/eclipse.ini file for setting heap size (thanks belial6)
    Edit 2: Added javah to update-alternatives list (thanks anarhistu)
    Edit 3: Clarified discussion on Eclipse bug (thanks anarhistu for pointing out this was unclear)
    Edit 4: Use update-java-alternatives instead of update-alternatives. (thanks korny)
    Edit 5: Updated java to version 6
    Edit 6: Updated eclipse ini path for feisty users (thanks biTaZ and ksenos)
    Last edited by hod139; September 10th, 2008 at 03:27 AM. Reason: Updated from dapper to hardy
    When I invented the Web, I didn't have to ask anyone's permission.
    ~Tim Berners-Lee on Net Neutrality
    -------------------------------------
    Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).

  2. #2
    Join Date
    Jan 2006
    Beans
    3

    Re: Installing and setting up Eclipse with Sun's Java

    For me Eclipse was very slow because the default heap size was relatively small. So I increased the heap.

    Since I have 1 gig of ram I put max heap to 256 MB and default to 100MB.

    Here is what I changed in /usr/bin/eclipse script (that's where my eclipse startup script is):
    Before there weren't any vm arguments
    VMARGS=""

    Changed it to this
    VMARGS="-Xms100m -Xmx256m"


    And now eclipse is running much faster. Before I had problems working with just 5 editor windows open. Now I can easily open 20 of them 8)

  3. #3

    Re: Installing and setting up Eclipse with Sun's Java

    Ok, I wanted to post this, but I will just complete your post:

    Lastly, Eclipse for some reason ignores Ubuntu's JVM configuration file and uses its own (bug?). You need to edit eclipes's java_home file
    Code:

    sudo -b gedit /etc/eclipse/java_home
    Well, this is because of the Eclipse init script.Let's look at the script a little (/usr/bin/eclipse) :

    Code:
    .....
    # If the user has specified a custom JAVA, we check it for validity.
    # JAVA defines the virtual machine that Eclipse will use to launch itself.
    if [ -n "${JAVA_HOME}" ]; then
        echo "using specified vm: ${JAVA_HOME}"
    
    .....
    
    # If the user has not set JAVA_HOME, cycle through our list of compatible VM's
    # and pick the first one that exists.
    if [ -z "${JAVA_HOME}" -a ! -n "${JAVACMD}" ]; then
        echo "searching for compatible vm..."
        javahomelist=`cat /etc/eclipse/java_home  | grep -v '^#' | grep -v '^$' | while read line ; do echo -n $line ; echo -n ":" ; done`
        OFS="$IFS"
        IFS=":"
        for JAVA_HOME in $javahomelist ; do
            echo -n "  testing ${JAVA_HOME}..."
    ....

    Ok, so what we see here is this: Eclipse searches for the Environment variable named JAVA_HOME which you should have set.If it does not find it, it will go through the vm-s in its list /etc/eclipse/java_home.

    So, we try to see if the script works:

    Code:
    ~$ export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun 
    $ eclipse
    using specified vm: /usr/lib/jvm/java-1.5.0-sun
    ........
    That is, the script works just fine if you set the env variable.

    For a permanent setting add it to ~/.bashrc or ~/.bash_profile or whatever you use for your profile (I think .bashrc is default)

    PS: At configuring the update alternatives.You can just do the old way and simbolic link applications in /usr/bin to the correct applications.Like :
    Code:
    ln -sf /usr/lib/jvm/java-1.5.0-sun/bin/java java
    I don't know if it is correct or not, but this is how I did it.
    And I also have a javah in my /usr/bin maybe you should list that too in your list.

    Greets,
    Matei

  4. #4
    Join Date
    Jul 2005
    Beans
    1,535
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Installing and setting up Eclipse with Sun's Java

    Quote Originally Posted by belial6
    For me Eclipse was very slow because the default heap size was relatively small. So I increased the heap.

    Since I have 1 gig of ram I put max heap to 256 MB and default to 100MB.

    Here is what I changed in /usr/bin/eclipse script (that's where my eclipse startup script is):
    Before there weren't any vm arguments
    VMARGS=""

    Changed it to this
    VMARGS="-Xms100m -Xmx256m"


    And now eclipse is running much faster. Before I had problems working with just 5 editor windows open. Now I can easily open 20 of them 8)
    Correct me if I'm wrong, but doesn't eclipse read
    Code:
    /usr/share/eclipse/eclipse.ini
    for JVM settings, and the default in dapper is
    Code:
    -vmargs
    -Xms40m
    -Xmx256m
    Thanks for the suggestion though of making people aware of this file. I will edit my original post.
    When I invented the Web, I didn't have to ask anyone's permission.
    ~Tim Berners-Lee on Net Neutrality
    -------------------------------------
    Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).

  5. #5
    Join Date
    Nov 2005
    Beans
    Hidden!
    Distro
    Ubuntu 6.06

    Re: Installing and setting up Eclipse with Sun's Java

    Just wanted to confirm this worked great in xubuntu dapper. Eclipse opened much faster than ever, dunno if xfce or the Xms Xmx settings were the kickers, but I'm happy!

    Thanks
    "Life is the fire in which we burn."
    3 Links everyone should have bookmarked:
    Linux Doc Project Freshmeat - Package Heaven Eric S. Raymond's site

  6. #6
    Join Date
    Apr 2006
    Beans
    21

    Re: Installing and setting up Eclipse with Sun's Java

    I have an example of a script that sets JAVA_HOME from the update-alternatives controlled path at http://www.ubuntuforums.org/showthre...84#post1296484

    - possibly putting this script in your .bashrc might be more reliable than manually setting JAVA_HOME? Be warned, I haven't really played around with it much.

    Also, generally it's better to call update-java-alternatives than update-alternatives - it calls update-alternatives for each of the java programs, not just java and javah.

    When I've had a chance to test this properly, I might write it up as a howto...

  7. #7
    Join Date
    Jul 2005
    Beans
    1,535
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Installing and setting up Eclipse with Sun's Java

    Quote Originally Posted by korny View Post
    I have an example of a script that sets JAVA_HOME from the update-alternatives controlled path at http://www.ubuntuforums.org/showthre...84#post1296484

    - possibly putting this script in your .bashrc might be more reliable than manually setting JAVA_HOME? Be warned, I haven't really played around with it much.

    Also, generally it's better to call update-java-alternatives than update-alternatives - it calls update-alternatives for each of the java programs, not just java and javah.

    When I've had a chance to test this properly, I might write it up as a howto...
    Thanks for the feedback. I changed my post to use update-java-alternatives. I'm not going to add your script to my main post since there already exists
    Code:
    /usr/share/java-common/jvm-find.sh
    and I'm trying to make a minimal set of changes with the smallest amount of side effects to deal with the known ubuntu bugs. That way upgrades shouldn't be an issue. Hopefully Ubuntu will have the java-common and java-alternatives working better by 6.10.
    When I invented the Web, I didn't have to ask anyone's permission.
    ~Tim Berners-Lee on Net Neutrality
    -------------------------------------
    Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).

  8. #8
    Join Date
    Apr 2006
    Beans
    21

    Re: Installing and setting up Eclipse with Sun's Java

    fair enough - my only problem with that script is that it falls back to /etc/jvm, which is a parallel and alternative way of selecting JVMs to the update-alternatives way.
    If people reliable edit /etc/jvm at the same time as running update-alternatives, this will work fine. I just wish these things could be set in one place!

    /etc/jvm is actually slightly nicer in some ways, as it allows a user to override the system-wide default - but it will only work with ubuntu or debian packaged apps; command-line calls to java, or manually installed apps, will typically look for JAVA_HOME, or rely on the "java" command in the path.

  9. #9
    Join Date
    Jul 2005
    Beans
    1,535
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Installing and setting up Eclipse with Sun's Java

    Quote Originally Posted by korny View Post
    I just wish these things could be set in one place!
    I agree 100%
    When I invented the Web, I didn't have to ask anyone's permission.
    ~Tim Berners-Lee on Net Neutrality
    -------------------------------------
    Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).

  10. #10
    Join Date
    Dec 2005
    Beans
    7

    Re: Installing and setting up Eclipse with Sun's Java

    Very good howto! I have been waiting for this for a while.

    It should be one big bug report for update-java-alternatives.

Page 1 of 9 123 ... LastLast

Bookmarks

Posting Permissions

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