2012-02-23 6 views

答えて

3

JDKからの一般的なネットワークアクセスの場合、起動時にJDKの引数を渡すこともできます。

ような何か:多くの場合、よりよい解決策は、あなたの設定ファイルから読んだ値を使用して、アプリケーション内でプログラム的にオプションを設定されている

java -Dhttp.proxyHost=myproxy.com -Dhttp.proxyPort=8080 ... MyTransformerClass 

。以下のような

何か:

System.setProperty("http.proxyHost", myConfig.getProxyHost()); 
System.setProperty("http.proxyPort", myConfig.getProxyPort()); 

それは持っていることはほとんど常により良いですすべてのオプション

ただし、XSDを解決する必要があるXML処理の具体的な例では、DTDなどのためhttp://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.htmlを参照してください。ローカルのコピーを試してみて、パーサーにjavax.xml.stream.XMLResolverを指定して、リモートではなくローカルのコピーをロードしてください。

+0

ありがとう、ちょうど私が必要なもの! – STM

1

アプリケーションでプロキシを設定する必要があります。

まず、あなたはこのようなjava.net.Authenticatorを拡張するクラスを作成する必要があります。

import java.net.Authenticator; 
import java.net.PasswordAuthentication; 

public class SimpleAuthenticator extends Authenticator { 

    private String username, password; 

    public SimpleAuthenticator(String username, String password) { 

     this.username = username; 
     this.password = password; 
    } 

    protected PasswordAuthentication getPasswordAuthentication() { 

     return new PasswordAuthentication(username, password.toCharArray()); 
    } 
} 

第二に、あなたのコード内で認証を初期化します。

SimpleAuthenticator sm = new simpleAuthenticator("user", "pass") 
Authenticator.setDefault(sm); 

第三に、ポートを通過し、システムプロパティとしてプロキシをあなたのアプリケーションに。 jettyとmavenの場合は、次のようになります。

関連する問題