无法在Java中解析DatatypeConverter类。

huangapple go评论85阅读模式
英文:

Cannot resolve DatatypeConverter class in java

问题

以下是代码的翻译部分:

@Override
public String generateHash(String plainTextPassword) {

    String hashedPassword = "";
    try {
        MessageDigest msdDigest = MessageDigest.getInstance("SHA-1");
        msdDigest.update(plainTextPassword.getBytes("UTF-8"), 0, plainTextPassword.length());
        hashedPassword = DatatypeConverter.printHexBinary(msdDigest.digest());
    } catch (Exception e) {
        System.out.println("HASHING FAILED");
    }
    return hashedPassword;
}

在我的本地机器上,我使用DatatypeConverter类没有问题。该包为javax.xml.bind.DatatypeConverter; 当我将项目转移到运行Ubuntu的Linux机器上时,无法解析DatatypeConverter类。

英文:

I have the following code to generate an SHA-1 hash.

@Override
	public String generateHash(String plainTextPassword) {

		String hashedPassword = "";
		try {
			MessageDigest msdDigest = MessageDigest.getInstance("SHA-1");
			msdDigest.update(plainTextPassword.getBytes("UTF-8"), 0, plainTextPassword.length());
			hashedPassword = DatatypeConverter.printHexBinary(msdDigest.digest());
		} catch (Exception e) {
			System.out.println("HASHING FAILED");
		}
		return hashedPassword;
	}

On my local machine, I have no problem using the DatatypeConverter class. The package is javax.xml.bind.DatatypeConverter; When I transfer my project over to a linux machine running Ubuntu, the DatatypeConverter class is not resolved.

答案1

得分: 16

以下是翻译好的部分:

模块 javax.xml.bind 已经从 Java 9 开始移出了 JDK。

另外,作为将 Java EE 捐赠给 Eclipse 基金会的一部分,它的新名称是 Jakarta EE,相应的命名空间也改名为 Jakarta。因此,您需要进行以下修改:

将依赖项添加到您的项目中:

使用 Maven,将以下内容添加到您的 pom.xml 文件中:

<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>3.0.0</version>
</dependency>

使用 Gradle,将以下内容添加到您的 build.gradle 文件中:

implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api-parent', version: '3.0.0', ext: 'pom'

在您使用该依赖的 Java 代码中,将导入语句更改为:

import jakarta.xml.bind.DatatypeConverter;
英文:

The module javax.xml.bind has been put outside the jdk as of Java 9.

Also, as part of the donation of Java EE to the Eclipse Foundation, its new name is Jakarta EE and accordingly the namespace was renamed to Jakarta. So you have to make the following modifications :

Add the dependency to your project :

With Maven, add the following to your pom.xml :

&lt;dependency&gt;
    &lt;groupId&gt;jakarta.xml.bind&lt;/groupId&gt;
    &lt;artifactId&gt;jakarta.xml.bind-api&lt;/artifactId&gt;
    &lt;version&gt;3.0.0&lt;/version&gt;
&lt;/dependency&gt;

With Gradle, add the following to your build.gradle :

implementation group: &#39;jakarta.xml.bind&#39;, name: &#39;jakarta.xml.bind-api-parent&#39;, version: &#39;3.0.0&#39;, ext: &#39;pom&#39;

And, in your java code where the dependence is used, change the import to :

import jakarta.xml.bind.DatatypeConverter;

huangapple
  • 本文由 发表于 2020年4月9日 00:00:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/61104983.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定