Download NetBeans!

20050822 Monday August 22, 2005

About that proxy server ... (Part 2)

In yesterday's blog entry I felt all pleased because I'd worked out how to set the proxy host and port number for NetBeans J2SE projects. This is what I did:

  1. Create my.properties file in my application's root directory.
  2. Add proxy host and port number to the my.properties file:

    http.proxyHost:webcache.uk
    http.proxyPort:8080
  3. Right-click the project, choose Properties, click Run, and type my.properties in the Arguments field.
  4. Add this to the project's main class:

     if (args.length != 1) {
       System.err.println("Where's your properties file?");
       System.exit(1);
     }
            
     // Retrieve settings from the properties file,
     // add to system properties
     Properties myprops = new Properties();
     myprops.load(new FileInputStream(args[0]));
            
     Properties props = System.getProperties();
            
     Enumeration propNames = myprops.propertyNames();
     while (propNames.hasMoreElements()) {
        String s = (String) propNames.nextElement();
        props.setProperty(s, myprops.getProperty(s));
     }

However, then I re-read Brian Leonard's Running the Amazon Web Services Sample Application In NetBeans and realized that all I really needed to do (instead of creating the my.properties file, putting it in the project's Arguments field, and adding a whole bunch of code to the main method) was add the proxy host and port number to the project's VM Options field (click to enlarge):

-Dhttp.proxyHost=webcache.uk -Dhttp.proxyPort=8080

Sometimes life is a lot simpler than it seems!

And why is this blog entry called "About that proxy server ...(Part 2)"? Where's Part 1? Well, Gregg wrote that: About that proxy server ... That blog entry looks at the proxy server for web-based clients, while this looks at it from the perspective of a Java application.

Aug 22 2005, 03:04:58 AM PDT Permalink