title: Getting java.net.ConnectException: Connection refused: connect in eclipse
body: <p>I am getting java.net.ConnectException: Connection refused: connect in eclipse.
  I am working behind corporate proxy settings.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import java.net.*;
  import java.io.*;
  
  public class URLConnectionReader {
      public static void main(String[] args) throws Exception {
          URL oracle = new URL("http://www.oracle.com/");
          URLConnection yc = oracle.openConnection();
          BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
          String inputLine;
          while ((inputLine = in.readLine()) != null)
              System.out.println(inputLine);
          in.close();
      }
  }
  </code></pre>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>   Exception in thread "main" java.net.ConnectException: Connection refused: connect
  at java.net.DualStackPlainSocketImpl.connect0(Native Method)
  at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  at java.net.Socket.connect(Socket.java:589)
  at java.net.Socket.connect(Socket.java:538)
  at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
  at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
  at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
  at sun.net.www.http.HttpClient.&lt;init&gt;(HttpClient.java:242)
  at sun.net.www.http.HttpClient.New(HttpClient.java:339)
  at sun.net.www.http.HttpClient.New(HttpClient.java:357)
  at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1202)
  at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)
  at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)
  at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:966)
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
  at URLConnectionReader.main(URLConnectionReader.java:9)
  </code></pre>
  
  <p>I have set the proxy setting in Preference-->Network Setting as shown in image below. </p>
  
  <p><a href="https://i.stack.imgur.com/T0SxM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T0SxM.png" alt="enter image description here"></a></p>