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






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