WHAT'S NEW?
Loading...

Font rendering for Java applications in Linux

There are many softwares built with java that require jvm to run.  For developers,  mainly IDEs are of great concern.  But with the Oracle java jre,  the font rendering looks so weird that the fonts look so much pixelated even after trying some tweaks that are found everywhere on internet on this issue. 

What is the problem?
 
This is the problem of Oracle java version. Most IDEs come with included jvm these days. And they contain the Oracle java version.  Most of IDEs come in a zip or tar.gz bundle and most of us extract them and start using them directly. If some configuration can be made before that,  we can feel the nice font rendering in them even in Linux. 

More detail about problem

This font rendering is fixed in open-jdk version of Java.  Even after installing and selecting open-jdk as currently active java in our system,  the IDEs don't use the jvm installed on our system. They are still using the jvm that is included in the IDE home directory.  During runtime, there is a script that checks for using which jvm.  If some environment variable is set to your system required by the IDE,  the IDE will use the open-jdk version of jvm and if it isn't set,  it uses the jvm that is bundled with the IDE. If there is open-jdk version already bundled with the IDE,  it is not necessary to configure environment variable. This was found in the Linux distribution of Android Studio 2.2 preview 1 version. The version of open-jdk required for proper font rendering is open-jdk-8.

How to install open-jdk and select it as default java in Ubuntu Linux?

Add the repo for openjdk-8
sudo add-apt-repository ppa:openjdk-r/ppa
Run update and install openjdk-8
sudo apt-get update 

sudo apt-get install openjdk-8-jdk
If you have more than one java versions installed, select the default java with this command.
sudo update-alternatives --config java
Select java version from the prompt displayed. Do the same for javac with this command
sudo update-alternatives --config javac 

How to set environment variable?

Go to home directory of user by
cd ~
edit .bashrc file 
vi .bashrc

navigate to the end of file and add following paths, path is the path to your openjdk installation
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_HOME
For jetbrains products,
WEBIDE_JDK=/usr/lib/jvm/java-8-openjdk-amd64
export WEBIDE_JDK
For netbeans,
netbeans_jdkhome=/usr/lib/jvm/java-8-openjdk-amd64
export netbeans_jdkhome
 
How to run from terminal?
 
Navigate to the directory than contains the launcher script.  The following are launcher scripts for popular IDEs in use:
Now, the command is like:
./script.sh

This will now give you the expected font rendering for IDEs like NetBeans,  PhpStorm,  WebStorm,  IntelliJIdea,  etc. 

Wait,  Still problem running from desktop entry? 

Yes,  even after making these changes and configuration,  you will be unable to run the IDEs from desktop entry launchers.  For this find the desktop entry launcher in your system. 

It is located in /usr/share/applications folder if the desktop entry was created for all users.  If it is created only for current user it is located in ~/. local/share/applications.  For editing desktop entry,  use a text editor.  To make changes go desktop entry in /usr/share/applications,  you need root access. 
Find the line with exec command and modify it to:
Exec=bash -i "path_to_script.sh" %f

ENJOY THE BETTER RENDERED FONT AND BETTER OPERATING SYSTEM

0 comments:

Post a Comment