Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve DatatypeConverter class in java

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.

like image 477
Isaiah Dicristoforo Avatar asked Mar 08 '26 18:03

Isaiah Dicristoforo


1 Answers

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;
like image 195
Pierre C Avatar answered Mar 10 '26 09:03

Pierre C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!