Javaアプリケーションでプロキシを設定する必要がある場合、以下の方法で設定できます。
システムプロパティを使用する
Javaは、システムプロパティを介してプロキシの設定を可能にしています。以下は、プロキシを設定するための例です。
public class ProxyExample {
    public static void main(String[] args) {
        // プロキシのホストとポートを指定
        System.setProperty("http.proxyHost", "proxy.example.com");
        System.setProperty("http.proxyPort", "8080");
        // HTTPSプロキシの設定も可能
        System.setProperty("https.proxyHost", "proxy.example.com");
        System.setProperty("https.proxyPort", "8080");
        // プロキシをバイパスするホストを設定(任意)
        System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1");
        // ここからアプリケーションのコードを続ける
    }
}
これにより、Javaアプリケーションは指定されたプロキシを使用して通信します。プロキシを使用しない特定のホストがある場合は、http.nonProxyHostsにそれらのホストを指定します。
プロパティファイルを使用する
別の方法として、プロキシの設定をプロパティファイルに記述し、それを読み込む方法があります。
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class ProxyExampleWithFile {
    public static void main(String[] args) {
        try {
            // プロパティファイルを読み込む
            Properties properties = new Properties();
            properties.load(new FileInputStream("proxy.properties"));
            // プロキシの設定を取得
            String proxyHost = properties.getProperty("http.proxyHost");
            String proxyPort = properties.getProperty("http.proxyPort");
            // プロキシを設定
            System.setProperty("http.proxyHost", proxyHost);
            System.setProperty("http.proxyPort", proxyPort);
            // ここからアプリケーションのコードを続ける
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
プロパティファイル(例: proxy.properties)には次のようにプロキシの情報を記述します。
http.proxyHost=proxy.example.com
http.proxyPort=8080
これにより、プロパティファイルを変更するだけでプロキシの設定を簡単に変更できます。