Java NoClassDefFoundError sun/io/ByteToCharConverter with InterBase JDBC driver

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25365952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:13:32  来源:igfitidea点击:

NoClassDefFoundError sun/io/ByteToCharConverter with InterBase JDBC driver

javajdbcjava-8interbase

提问by mjn

With InterClient 7.5.1 and 8.1.5, the creation of a new JDBC connection in Java 8 fails with

使用 InterClient 7.5.1 和 8.1.5,在 Java 8 中创建新的 JDBC 连接失败

java.lang.NoClassDefFoundError: sun/io/ByteToCharConverter

This class seems to be referenced or used by the InterClient JDBC library. The error does not occur with Java 7. Is there a way to work around this error?

InterClient JDBC 库似乎引用或使用了此类。Java 7 不会出现此错误。有没有办法解决此错误?



This code reproduces the problem on Java 8:

此代码重现了 Java 8 上的问题:

package com.example.so25365952;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {
    interbase.interclient.Connection conn; 

    public static void main(String[] args) {
        try {
            Class.forName("interbase.interclient.Driver");           
            DriverManager.getConnection("jdbc:interbase://localhost/data/mydb.gdb", "sysdba", "password123");           
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

Output:

输出:

Exception in thread "main" java.lang.NoClassDefFoundError: sun/io/ByteToCharConverter at interbase.interclient.Connection.connect(Unknown Source) at interbase.interclient.Connection.(Unknown Source) at interbase.interclient.Driver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at com.example.so25365952.Main.main(Main.java:14) Caused by: java.lang.ClassNotFoundException: sun.io.ByteToCharConverter at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 6 more

线程“main”中的异常 java.lang.NoClassDefFoundError: sun/io/ByteToCharConverter at interbase.interclient.Connection.connect(Unknown Source) at interbase.interclient.Connection.(Unknown Source) at interbase.interclient.Driver.connect(Unknown) Source) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at com.example.so25365952.Main.main(Main.java:14) 引起作者:java.lang.ClassNotFoundException:sun.io.ByteToCharConverter 在 java.net.URLClassLoader$1.run(URLClassLoader.java:372) 在 java.net.URLClassLoader$1.run(URLClassLoader.java:361) 在 java.security。 AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 6 更多

采纳答案by Kayaman

The sun.* and sunw.* packages are internal and should not be used for exactly this reason. Seems like someone at InterClient screwed up. I'd advise you to contact them with a bug report, so they'll know to fix this for future releases.

sun.* 和 sunw.* 包是内部的,因此不应使用。好像 InterClient 的某个人搞砸了。我建议您通过错误报告与他们联系,以便他们知道在将来的版本中修复此问题。

If you can't wait for a future release, and are willing to break some licences (which I don't recommend of course). You may be able to create your own sun.io.ByteToCharConverter by copying the code from here, and adding it to the bootstrap classpath with -Xbootclasspath, but that would be a last resort.

如果您迫不及待地等待未来的发布,并且愿意打破一些许可证(我当然不建议这样做)。您可以通过复制此处的代码来创建自己的 sun.io.ByteToCharConverter ,然后使用 将其添加到引导类路径中-Xbootclasspath,但这将是最后的手段。

回答by alizelzele

sun.io.ByteToCharConvertorwas deprecated in java 7. and it seems they remove it in java 8.

sun.io.ByteToCharConvertor在 java 7 中被弃用。似乎他们在 java 8 中删除了它。

回答by mjn

The answer to the question interbase.interclient.UnlicensedComponentException with the latest interclient.jar IB (v7.5.80)seems to work for me too. It suggests to use version 1.5 of the JDBC driver for Firebird. Fortunately this driver does not rely on deprecated sun classes and works with JRE 8.

问题interbase.interclient.UnlicensedComponentException 与最新的 interclient.jar IB (v7.5.80)的答案似乎也对我有用。它建议对 Firebird 使用 JDBC 驱动程序的 1.5 版。幸运的是,此驱动程序不依赖于已弃用的 sun 类并且可与 JRE 8 配合使用。

回答by Vinod Kotha

use db2jcc4.jar which is latest version. if you changed your mind to use Java8 you need to use this. I have the similirar problem and this change help me to fix the error.

使用最新版本的 db2jcc4.jar。如果您改变主意使用 Java8,则需要使用它。我有类似的问题,此更改帮助我修复错误。

回答by Sergio

This is an old question, but in case this helps someone:

这是一个老问题,但万一这有助于某人:

Find the Java 7 rt.jar in the lib folder. Open the file, and go to the folder sun/io.

在 lib 文件夹中找到 Java 7 rt.jar。打开文件,然后转到文件夹 sun/io。

Find the Java 8 rt.jar in the lib folder. Open the file, and go to the folder sun/io.

在 lib 文件夹中找到 Java 8 rt.jar。打开文件,然后转到文件夹 sun/io。

Move all the .class files in the folder sun/io from the Java 7 to the Java 8 sun/io folder, except for Win32ErrorMode.class (this class was in both jar files).

将文件夹 sun/io 中的所有 .class 文件从 Java 7 移动到 Java 8 sun/io 文件夹,Win32ErrorMode.class 除外(此类在两个 jar 文件中)。

Save the Java 8 rt.jar with the added classes.

使用添加的类保存 Java 8 rt.jar。

This worked for me, using an old jdbc driver for SQL Server.

这对我有用,为 SQL Server 使用旧的 jdbc 驱动程序。

回答by androclus

I agree with Sergio, this is now an even older question! :-) But at my workplace, too, we are unfortunately as of 2018 for various reasons still using a super-old Interbase (v9, 2009). So at some point I too was unable to continue using the interclient.jar packaged with IBv9, because I would receive this same sun.io.ByteToCharConverter error. No doubt this was because the Java on my client machine was so much newer now. After all, it is9 years later. But I did not want in my case to go with the solution of installing a legacy Java on my machine, as has worked for others.

我同意塞尔吉奥的观点,这是一个更古老的问题!:-) 但在我的工作场所也是如此,不幸的是,由于各种原因,我们在 2018 年仍在使用超旧的 Interbase(v9,2009)。所以在某些时候我也无法继续使用与 IBv9 一起打包的 interclient.jar,因为我会收到同样的 sun.io.ByteToCharConverter 错误。毫无疑问,这是因为我的客户端机器上的 Java 现在更新了很多。毕竟9年后。但在我的情况下,我不想采用在我的机器上安装遗留 Java 的解决方案,因为其他人已经这样做了。

So as a solution, on my client machine (Linux/Debian x64), I installed Interbase 2017, the latest at the time(*). But when installing, I only installed the IB Client (not Server + Client). The /opt/interbase/lib/interclient.jar that is packaged with the IB 2017 client works just fine now (no sun.io error). And yes, this IB 2017 (v13) interclient.jar works just fine connecting to our old IB 2009 server.

因此,作为解决方案,在我的客户端计算机 (Linux/Debian x64) 上,我安装了当时最新的 Interbase 2017(*)。但是在安装的时候,我只安装了IB Client(不是Server + Client)。与 IB 2017 客户端一起打包的 /opt/interbase/lib/interclient.jar 现在工作正常(没有 sun.io 错误)。是的,这个 IB 2017 (v13) interclient.jar 可以很好地连接到我们旧的 IB 2009 服务器。

(I have to hand it to Embarcadero: They are still 'supporting' being able to connect to older versions -- at least in their interclient.jar and libgds.so. This makes sense as useful of course for those sysadmins who want to migrate from older systems to newer ones.)

(我必须把它交给 Embarcadero:他们仍然“支持”能够连接到旧版本——至少在他们的 interclient.jar 和 libgds.so 中。这当然对那些想要迁移的系统管理员有用从旧系统到新系统。)

(*) You can get a free trial version of Interbase from embarcadero. As far as I can tell, though, when you install it, if you install the Client only and use the interclient.jar, this does not require a license. Only installing the IB server (and depending on number of users/connections, etc) but that is nothing new to IB users/admins.

(*) 您可以从 embarcadero获得Interbase免费试用版。不过,据我所知,当你安装它时,如果你只安装客户端并使用 interclient.jar,这不需要许可证。只安装 IB 服务器(取决于用户/连接的数量等),但这对 IB 用户/管理员来说并不是什么新鲜事。

Works for us, at least, until we upgrade our server's IB version, or move to Firebird.

至少在我们升级服务器的 IB 版本或迁移到 Firebird 之前对我们有用。

Hope this helps at least one other person out there.

希望这可以帮助至少另一个人。

回答by zain wang

use

<!-- https://mvnrepository.com/artifact/com.ibm.db2.jcc/db2jcc -->
        <dependency>
            <groupId>com.ibm.db2.jcc</groupId>
            <artifactId>db2jcc</artifactId>
            <version>db2jcc4</version>
        </dependency>

replace

代替

<dependency>
            <groupId>com.ibm.db2.jcc</groupId>
            <artifactId>db2jcc</artifactId>
            <version>10.1</version>
        </dependency>

can Solve the problem

可以解决问题