简体   繁体   English

sun.net.www.protocol.file 将代码从 1.6 jdk 迁移到 11 jdk 问题

[英]Migration code from 1.6 jdk to 11 jdk problem with sun.net.www.protocol.file

I have a problem with migration old code which used sun.net.* and sun.net.www.protocol.file.FileURLConnection Ant cannot build project on jdk 11 because FileURLConnection is from version 8/9 internal class of base package.我有迁移旧代码的问题,它使用sun.net.*sun.net.www.protocol.file.FileURLConnection Ant 无法在 jdk 11 上构建项目,因为FileURLConnection来自版本 8/9 内部 class 基础 ZEFE86B70A8E604A67C FileURLCOnnection was use to check instance of returned class so I will need good idea how I can replace this fragment without destroing logic (fragment belowe). FileURLCONnection 用于检查返回的 class 的实例,所以我需要知道如何在不破坏逻辑的情况下替换这个片段(下面的片段)。

connection instanceof FileURLConnection
    for (URL url = null; resources.hasMoreElements()
                && ((url = resources.nextElement()) != null); ) {
                try {
                    connection = url.openConnection();

                    if (connection instanceof JarURLConnection) {
                        checkJarFile((JarURLConnection) connection, pckgname,
                            classes);
                    } else if (connection instanceof FileURLConnection) {
                        try {
                            checkDirectory(
                                new File(URLDecoder.decode(url.getPath(),
                                    "UTF-8")), pckgname, classes);
                        } catch (final UnsupportedEncodingException ex) {
                            throw new ClassNotFoundException(
                                pckgname
                                    + " does not appear to be a valid package (Unsupported encoding)",
                                ex);
                        }
                    } else
                        throw new ClassNotFoundException(pckgname + " ("
                            + url.getPath()
                            + ") does not appear to be a valid package");
                } catch (final IOException ioex) {
                    throw new ClassNotFoundException(
                        "IOException was thrown when trying to get all resources for "
                            + pckgname, ioex);
                }
            }

You should be able to replace:您应该能够替换:

connection instanceof FileURLConnection

By:经过:

"file".equals(url.getProtocol())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM