我正在尝试通过代理脚本连接到 URL。 所以我使用以下代码:
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);
}
我可以运行代码。 但是当我尝试使用 Maven 构建它时,出现错误:
package com.sun.deploy.net.proxy does not exist
[ERROR] /.../App.java:[135,17] cannot find symbol
[ERROR] symbol: class BrowserProxyInfo
我没有找到任何关于 com.sun.deploy.net.proxy
的 Maven 依赖项添加到 pom 中。
这是我的 java 信息:
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)
这是我的 Maven 构建:
<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>
我还没有找到任何其他方法来通过代理脚本连接到 URL。 您对这个问题有什么想法吗?或者其他连接方式?
最佳答案
您在类路径中缺少deploy.jar,您需要下载并设置maven依赖项。
首先下载deploy.jar:https://github.com/barchart/barchart-oracle-study/blob/master/oracle-jdk-7.21-deploy/deploy.jar
在maven依赖中添加下载的jar(pom.xml):
<dependency>
<groupId>com.user.deploy</groupId>
<artifactId>deploy-jar</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath><jar path></systemPath>
</dependency>
您甚至可以在 maven 本地存储库中安装此 jar:
阅读:Maven: best way of linking custom external JAR to my project?
关于java - com.sun.deploy.net.proxy 包不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231483/