Monday, August 25, 2014

How to build Selenium server standalone jar from Source

If you looking for the way to create a standalone executable jar looks like selenium-server-standalone-2.40.0.jar , which can be run with command 'java -jar selenium-server-standalone-2.40.0.jar', from selenium source code, then here is the answer for you.

What you need before start

  • JDK 1.7 (not JRE!)
  • Git
It seems unreasonable to need git for compiling, but the build script of Selenium (for now 2.40.0) will report error if you don't have git in path. 
Also, make sure you have your jdk in you path, which means you can run commands like 'jar' or 'javac' in your dos/shell prompt.

Get Selenium Source code

There are 2 ways to get source code. You can choose any one you like.
  • Method 1: git clone 
// clone the source from github
git  clone  https://github.com/SeleniumHQ/selenium selenium_git

// List all tag
git tag  –l     

//checkout a certain tag (version), here is 'selenium-2.40.0'
git checkout tags/selenium-2.40.0 
  • Method 2: download zipped source package (recommend if you don't have a stable internet connection)
  1. Go to https://code.google.com/p/selenium/source/browse/
  2. Choose the version/tag you need.
  3. click "zip" or "tar.gz" to download an all-in-one package
  4. unzip the downloaded file to a local directory.  For this example I build selenium on windows, the directory I use for unpacking is d:\selenium_src. The directory will look like below.
  5. make the directory a git repository to make build script happy. Since the build script will call git command, it will report error if the source directory is not a git repository.
// go to selenium source dir
cd d:\selenium_src

// make it a git repository
git init

Download 3rd party library (recommend but optional)

The build script of selenium will automatically download the third party gecko library. So this step is optional, but If you have a trouble while compiling or have a slow or unstable connection. I suggest you download the libraries manually to make your life easier.

  • Go to these places:

  • Download the file respectively:
xulrunner-17.0.en-US.win32.sdk.zip
xulrunner-24.0.en-US.win32.sdk.zip
xulrunner-26.0.en-US.win32.sdk.zip
xulrunner-27.0.en-US.win32.sdk.zip
Notice: you need to pick up the file for your platform. Since I'm using windows, I download the win32 sdk. If you're in linux, choose the linux version sdk instead.

  • Unpack all SDKs to selenium gecko-xx dir
In selenium_src\third_party, there are more than one gecko-xx dirs(such as gecko-17, gecko-24...), put the content of sdk you just downloaded into the right platform subdir of each gecko-xx directory. 
For example the content of sdk xulrunner-17.0.en-US.win32.sdk.zip goes to selenium_src\third_party\gecko-17\win32.
Notice: when unzip the sdk package, remove the top level direcory in the zip file. The final directory hierarchy will look like this:


Run the build script ( 3 go commands )

Run the build script

# change to selenium source root
cd d:\selenium_src

# clean
go clean

# compile the source code
go //java/server/src/org/openqa/selenium/remote/server:server:uber //java/client/src/org/openqa/selenium:client-combined:uber

#  make the standalone jar
go release
If everything goes fine, you can find your selenium standalone jar file in dir <selenium source root>/build/dist like below






9 comments:

  1. I'm getting a "fatal: Needed a single revision" error when compiling :(
    It happens after this command:
    Compiling: //java/client/src/org/openqa/selenium/firefox:firefox as build\java\c
    lient\src\org\openqa\selenium\firefox\firefox.jar
    Uber-jar: //java/server/src/org/openqa/selenium/remote/server:server as build\ja
    va\server\src\org\openqa\selenium\remote\server\server-standalone.jar
    fatal: Needed a single revision

    ReplyDelete
    Replies
    1. Hi Stephen,

      There "fatal: Needed a single revision" messages come out from git. It becauses you may have .git directory in selenium source directory but have not specified a version to work on. There message will not break the compile process. If you just want to get the standalone executable jar file, you can just ignore the messages.

      It's not that "fatal" :D

      Delete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. I have to delete the comment due to the over length, make sure JDK has been properly install before compiling.

      Delete
  3. Simple Good and better thing it works perfectly ..Helped me alot thanks :)

    ReplyDelete
  4. I get a lot of "The system cannot find the path specified." when building, then it falls back to prebuild files. Then it aborts with this message "'jar' is not recognized as an internal or external command"

    ReplyDelete
    Replies
    1. Build no longer aborts, after adding correct SDK to the Path. I still see js files being skipped when compiling, and the file I need to change is skipped and falls back to recompiled.

      Delete
  5. HI,

    I have followed the above mentioned steps for building the selenium source code in the linux machine.
    When I ran the below command
    ./go clean

    I got below error
    fatal: Unable to mark file cpp/prebuilt/amd64/libimehandler64.so
    fatal: Unable to mark file cpp/iedriver/Generated/atoms.h

    It will be great if any one help me in this..
    Thanks in Advance

    ReplyDelete

Powered by Blogger.

About The Author

My Photo

Has been a senior software developer, project manager for 10+ years. Dedicate himself to Alcatel-Lucent and China Telecom for delivering software solutions.

Pages

Unordered List