Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old June 21st, 2006   #1
hod139
Fresh Brewed Ubuntu
 
Join Date: Jul 2005
Beans: 1,537
Ubuntu 8.04 Hardy Heron
Send a message via AIM to hod139
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)
__________________
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).

Last edited by hod139; September 9th, 2008 at 10:27 PM.. Reason: Updated from dapper to hardy
hod139 is offline   Reply With Quote
Old June 26th, 2006   #2
belial6
First Cup of Ubuntu
 
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
belial6 is offline   Reply With Quote
Old June 27th, 2006   #3
hod139
Fresh Brewed Ubuntu
 
Join Date: Jul 2005
Beans: 1,537
Ubuntu 8.04 Hardy Heron
Send a message via AIM to hod139
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
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).
hod139 is offline   Reply With Quote
Old September 9th, 2008   #4
spinlock99
5 Cups of Ubuntu
 
Join Date: Nov 2007
Location: Brooklyn, NY
Beans: 27
Ubuntu 7.10 Gutsy Gibbon
Re: Installing and setting up Eclipse with Sun's Java

Wow searching through old posts really works. This is exactly what I was trying to do. Thanks!

Quote:
Originally Posted by belial6 View Post
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"
Just one follow up question: "-Xmx256m" should (tm) set eclipse to use 256 megs of ram. What does "-Xms100m" do?

Thanks again.
spinlock99 is offline   Reply With Quote
Old September 9th, 2008   #5
hod139
Fresh Brewed Ubuntu
 
Join Date: Jul 2005
Beans: 1,537
Ubuntu 8.04 Hardy Heron
Send a message via AIM to hod139
Re: Installing and setting up Eclipse with Sun's Java

Quote:
Originally Posted by spinlock99 View Post
Just one follow up question: "-Xmx256m" should (tm) set eclipse to use 256 megs of ram. What does "-Xms100m" do?
Xms sets the minimum heap size, Xmx sets the maximum heap size.
__________________
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).
hod139 is offline   Reply With Quote
Old September 27th, 2008   #6
Znupi
Quad Shot of Ubuntu
 
Znupi's Avatar
 
Join Date: Feb 2007
Location: Bucharest
Beans: 457
Ubuntu 9.04 Jaunty Jackalope
Send a message via Yahoo to Znupi
Re: Installing and setting up Eclipse with Sun's Java

Hopefully no one will bash me for bumping an old thread.
I downloaded eclipse from eclipse.org and simply unpacked and ran it. It was painfully slow, so I found this thread and installed SUN's Java, but I can't edit the /etc/eclipse/java_home file, since there is no such file. If I go to Window -> Preferences -> Java -> Installed JREs there's only one in the list and it is /usr/lib/jvm/java-6-sun-1.6.0.06 . Does that mean Eclipse is using SUN's Java? If not, what can I do to make it use it? Thanks.
__________________
[ Blog # A Programmer's Ride ]
Linux: it really whips the penguin's butt.
Znupi is offline   Reply With Quote
Old September 28th, 2008   #7
hod139
Fresh Brewed Ubuntu
 
Join Date: Jul 2005
Beans: 1,537
Ubuntu 8.04 Hardy Heron
Send a message via AIM to hod139
Re: Installing and setting up Eclipse with Sun's Java

Quote:
Originally Posted by Znupi View Post
Hopefully no one will bash me for bumping an old thread.
I downloaded eclipse from eclipse.org and simply unpacked and ran it. It was painfully slow, so I found this thread and installed SUN's Java, but I can't edit the /etc/eclipse/java_home file, since there is no such file. If I go to Window -> Preferences -> Java -> Installed JREs there's only one in the list and it is /usr/lib/jvm/java-6-sun-1.6.0.06 . Does that mean Eclipse is using SUN's Java? If not, what can I do to make it use it? Thanks.
The configuration file /etc/eclipse/java_home is where the ubuntu package of eclipse puts it. You will have to find the corresponding file in your install location. To see which JRE eclipse is using, you should be able to (at least it works with the ubuntu package) run eclipse from the command line:
Code:
$ /usr/bin/eclipse 
searching for compatible vm...
  testing /usr/lib/jvm/java-gcj...not found
  testing /usr/lib/kaffe/pthreads...not found
  testing /usr/lib/jvm/java-6-sun...found
From the output, we see eclipse started with java-6-sun
__________________
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).
hod139 is offline   Reply With Quote
Old June 26th, 2006   #8
anarhistu
First Cup of Ubuntu
 
Join Date: Oct 2005
Beans: 7
Re: Installing and setting up Eclipse with Sun's Java

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

Quote:
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
anarhistu is offline   Reply With Quote
Old July 25th, 2006   #9
korny
5 Cups of Ubuntu
 
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...
korny is offline   Reply With Quote
Old July 25th, 2006   #10
hod139
Fresh Brewed Ubuntu
 
Join Date: Jul 2005
Beans: 1,537
Ubuntu 8.04 Hardy Heron
Send a message via AIM to hod139
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).
hod139 is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:30 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry