How can I set proxy in Chrome using selenium WebDriver?

Can anyone please guide me on how can I set proxy in Chrome using selenium WebDriver.

The easy and subtle way of achieving this in java is by using Desired Capabilities class.

This is quick and is something I used in one of the project too while performing automation testing services.

Here is a little snippet on how we did it.

//Set the obvious path property for Chrome driver.

System.setProperty("webdriver.chrome.driver", "C:\\Users\\XYZ\\Java\\chromedriver.exe");

// Create an object of DesiredCapabilities class

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

// Create an object for Proxy class

Proxy proxy = new Proxy();

//Now pass the proxy object to the capabilities by setting Capability

capabilities.setCapability("proxy", proxy);

//Pass the capabilities you have created to chrome driver object

ChromeDriver driver = new ChromeDriver(capabilities);

//Now navigate to any URL and voila.

driver.navigate().to("http://www.google.com");