How to Install the Right Version of Java to Run Selenium on a CentOS Server

By | May 27, 2014

If you want to launch Selenium on a Linux server, you need to have Java support installed.

If your Java version is lower than 1.6, most probably you will get the following error while trying to launch Selenium:

[root@ns1 selenium]# java -jar /usr/local/bin/selenium-server-standalone-2.41.0.jar -role hub
May 27, 2014 2:06:12 p.m. org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid server
Exception in thread “main” java.lang.NoSuchMethodError: method java.net.NetworkInterface.isLoopback with signature ()Z was not found.
at org.openqa.selenium.net.NetworkInterface.<init>(NetworkInterface.java:42)
at org.openqa.selenium.net.DefaultNetworkInterfaceProvider.createInterface(DefaultNetworkInterfaceProvider.java:75)
at org.openqa.selenium.net.DefaultNetworkInterfaceProvider.<init>(DefaultNetworkInterfaceProvider.java:51)
at org.openqa.selenium.net.NetworkUtils.<init>(NetworkUtils.java:38)
at org.openqa.grid.web.Hub.<init>(Hub.java:87)
at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:101)

In order to run is without errors, you need java-1.6.0, that is available with yum. In order to install it, you have to run the following command:

yum install java-1.6.0*

This will install OpenJDK stuff, needed to upgrade your Java. You will have to download about 400Mb of data. For me it was

========================================================================================================================================================================
Package                                           Arch                          Version                                           Repository                      Size
========================================================================================================================================================================
Installing:
java-1.6.0-openjdk                                x86_64                        1:1.6.0.0-5.1.13.3.el6_5                          updates                         41 M
java-1.6.0-openjdk-demo                           x86_64                        1:1.6.0.0-5.1.13.3.el6_5                          updates                        1.9 M
java-1.6.0-openjdk-devel                          x86_64                        1:1.6.0.0-5.1.13.3.el6_5                          updates                         15 M
java-1.6.0-openjdk-javadoc                        x86_64                        1:1.6.0.0-5.1.13.3.el6_5                          updates                         15 M
java-1.6.0-openjdk-src                            x86_64                        1:1.6.0.0-5.1.13.3.el6_5                          updates                         39 M
Installing for dependencies:
flac                                              x86_64                        1.2.1-6.1.el6                                     base                           243 k
giflib                                            x86_64                        4.1.6-3.1.el6                                     base                            37 k
jline                                             noarch                        0.9.94-0.8.el6                                    base                            86 k
libasyncns                                        x86_64                        0.8-1.1.el6                                       base                            24 k
libogg                                            x86_64                        2:1.1.4-2.1.el6                                   base                            21 k
libsndfile                                        x86_64                        1.0.20-5.el6                                      base                           233 k
libvorbis                                         x86_64                        1:1.2.3-4.el6_2.1                                 base                           168 k
pulseaudio-libs                                   x86_64                        0.9.21-14.el6_3                                   base                           462 k
rhino                                             noarch                        1.7-0.7.r2.2.el6                                  base                           778 k
tzdata-java                                       noarch                        2014b-3.24.el6                                    updates                        148 k

Transaction Summary
========================================================================================================================================================================
Install      15 Package(s)

After you install these packages, you can run your Selenium. The output should look like:

[root@ns1 selenium]# java -jar /usr/local/bin/selenium-server-standalone-2.41.0.jar
May 27, 2014 2:21:52 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
14:21:53.219 INFO – Java: Sun Microsystems Inc. 23.25-b01
14:21:53.220 INFO – OS: Linux 2.6.32-279.19.1.el6.x86_64 amd64
14:21:53.401 INFO – v2.41.0, with Core v2.41.0. Built from revision 3192d8a
14:21:53.738 INFO – Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: LINUX
14:21:54.264 INFO – RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
14:21:54.265 INFO – Version Jetty/5.1.x
14:21:54.266 INFO – Started HttpContext[/selenium-server/driver,/selenium-server/driver]
14:21:54.267 INFO – Started HttpContext[/selenium-server,/selenium-server]
14:21:54.267 INFO – Started HttpContext[/,/]
14:21:54.311 INFO – Started org.openqa.jetty.jetty.servlet.ServletHandler@380a81fd
14:21:54.312 INFO – Started HttpContext[/wd,/wd]
14:21:54.314 INFO – Started SocketListener on 0.0.0.0:4444
14:21:54.314 INFO – Started org.openqa.jetty.jetty.Server@1cde0cc2

Have fun!

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *