How to set proxy for Chrome browser in selenium using Java code

Passing a Capabilities object to the ChromeDriver() constructor is deprecated. You can find new official doc here.

ChromeOptions chromeOptions = new ChromeOptions();

Proxy proxy = new Proxy();
proxy.setAutodetect(false);
proxy.setHttpProxy("http_proxy-url:port"); 
proxy.setSslProxy("https_proxy-url:port");
proxy.setNoProxy("no_proxy-var");

chromeOptions.setCapability("proxy", proxy); 
driver = new ChromeDriver(chromeOptions);

Issue is resolved with below code -

Proxy proxy = new Proxy(); 
proxy.setHttpProxy("yoururl:portno"); 
proxy.setSslProxy("yoururl:portno"); 

DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
capabilities.setCapability("proxy", proxy); 

ChromeOptions options = new ChromeOptions(); 
options.addArguments("start-maximized"); 

capabilities.setCapability(ChromeOptions.CAPABILITY, options); 

driver = new ChromeDriver(capabilities);

Passing a Capabilities object to the ChromeDriver() constructor is deprecated. One way to use a proxy is this:

String proxy = "127.0.0.1:5000";
ChromeOptions options = new ChromeOptions().addArguments("--proxy-server=http://" + proxy);
WebDriver webDriver = new ChromeDriver(options);