java.lang.ClassCastException:com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl无法

编程入门 行业动态 更新时间:2024-10-26 06:39:38
本文介绍了java.lang.ClassCastException:com.sun.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl无法转换为javax.ssl.HttpsURLConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Netbeans 7.4中尝试了此代码,并且可以正常工作

I tried this code in my Netbeans 7.4 and it works without problem

import java.io.IOException; import java.URL; import javax.ssl.HttpsURLConnection; public class JavaApplication148 { public static void main(String[] args) throws IOException { URL url = new URL("redmine.ackee.cz/time_entries.xml"); HttpsURLConnection httpCon = (HttpsURLConnection) url.openConnection(); } }

但是后来我在Maven驱动的项目中的Eclipse中使用了它,并抛出了以下异常:

However then I used it in eclipse in my maven-driven project and it throws following exception :

java.lang.ClassCastException: com.sun.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl cannot be cast to javax.ssl.HttpsURLConnection

这是我的maven项目中的以下类,引发了错误

This is following class in my maven project that throws an error

package cz.ackee.redminemands; import java.io.IOException; import java.URL; import javax.ssl.HttpsURLConnection; public abstract class RedmineCommand { public void write(String xmlAddress, String text, String requestMethod) throws IOException{ URL url = new URL("redmine.xxx.cz/time_entries.xml"); HttpsURLConnection httpCon = (HttpsURLConnection) url.openConnection(); //this line throws exception } }

这是我的pom.xml

This is my pom.xml

<project xmlns="maven.apache/POM/4.0.0" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cz.ackee</groupId> <artifactId>pan-unicorn-bot</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Pan Unicorn Bot</name> <description>Pan unicorn IRC Bot</description> <repositories> <repository> <id>apache-snapshots</id> <url>repository.apache/snapshots/</url> </repository> </repositories> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.30</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.3.5.Final</version> </dependency> <dependency> <groupId>org.apachemons</groupId> <artifactId>commons-cli</artifactId> <version>1.3-SNAPSHOT</version> </dependency> <dependency> <groupId>com.taskadapter</groupId> <artifactId>redmine-java-api</artifactId> <version>1.23</version> </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <groupId>org.apache.maven.plugins</groupId> <version>2.3</version> <configuration> <source>1.7</source> <target>1.7</target> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2.1</version> <configuration> <descriptors> <descriptor>/src/main/assembly/binary.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.2</version> <configuration> <archive> <index>true</index> <manifest> <addClasspath>true</addClasspath> <mainClass>cz.ackee.unicorn.PanUnicornMain</mainClass> </manifest> <manifestEntries> <mode>development</mode> <url>${project.url}</url> <key>value</key> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build> </project>

任何想法,为什么它可以在netbeans上毫无问题地编译和运行,为什么它不能在maven-eclipse项目上正常运行?

Any idea, why it does compile and run without problem on netbeans and why it does not go well on maven-eclipse project?

(我使用mvn package通过命令行进行编译,通过eclipse运行它)

(I compile through command line using mvn package, I run it through eclipse)

推荐答案

解决方案是更改此行

URL url = new URL("redmine.xxx.cz/time_entries.xml");

进入此行

URL url = new URL(null, "redmine.xxx.cz/time_entries.xml", new sun.www.protocol.https.Handler());

更多推荐

java.lang.ClassCastException:com.sun.net.ssl.internal.www.protocol.https.HttpsUR

本文发布于:2023-10-31 05:13:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545106.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   sun   ssl   net   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!