英文:
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
:
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
With Gradle, add the following to your build.gradle
:
implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api-parent', version: '3.0.0', ext: 'pom'
And, in your java code where the dependence is used, change the import to :
import jakarta.xml.bind.DatatypeConverter;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论