Reputation: 496
I'm trying to connect to an URL through a proxy script. So I'm using the following code :
try {
URL myURL = new URL("https://aaa.com");
System.setProperty("java.security.policy", "policy.all");
System.setProperty("java.net.useSystemProxies", "true");
BrowserProxyInfo b = new BrowserProxyInfo();
b.setType(ProxyType.AUTO);
b.setAutoConfigURL("http://bbb.com/wpad.dat");
SunAutoProxyHandler handler = new SunAutoProxyHandler();
try {
handler.init(b);
ProxyInfo[] ps = handler.getProxyInfo(myURL);
for (ProxyInfo p : ps) {
System.out.println(p.toString());
}
} catch (ProxyConfigException e) {
log.error("error=> ProxyConfigException ", e);
} catch (ProxyUnavailableException e) {
log.error("error=> ProxyUnavailableException ", e);
}
URLConnection c = myURL.openConnection();
c.connect();
} catch (MalformedURLException e) {
log.error("error=> MalformedURLException ", e);
} catch (IOException e) {
log.error("error=> IOException ", e);
}
I can run the code. But when I try to build it with Maven I got an error :
package com.sun.deploy.net.proxy does not exist
[ERROR] /.../App.java:[135,17] cannot find symbol
[ERROR] symbol: class BrowserProxyInfo
I haven't find any maven dependencies about com.sun.deploy.net.proxy
to add in the pom.
Here are my java infos :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
This is my maven build :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.zzz</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}-full</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
</plugins>
I haven't found any other way to connect to an URL through a proxy script. Do you have any idea of this problem ? Or another way to connect ?
Upvotes: 0
Views: 7432
Reputation: 2035
You are missing deploy.jar in classpath, that you need to download and setup maven dependency.
First download deploy.jar: https://github.com/barchart/barchart-oracle-study/blob/master/oracle-jdk-7.21-deploy/deploy.jar
Add the downloaded jar in maven dependency(pom.xml):
<dependency>
<groupId>com.user.deploy</groupId>
<artifactId>deploy-jar</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath><jar path></systemPath>
</dependency>
You can even install this jar in maven local repository:
read: Maven: best way of linking custom external JAR to my project?
Upvotes: 2