DatatypeConverter and Java 9
If you used to do conversions, likeimport javax.xml.bind.DatatypeConverter;
...
byte[] bin = DatatypeConverter.parseHexBinary("0769cc");
With Java 9 you will get errors, since javax.xml.bind is no longer in the module path, it is considered part of Java Enterprise. With Java 10 it may even be removed from the JRE.
It is a known problem:
- https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j
- https://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java
Here I will focus on adding the dependency:
Java Enterprise library
As a Maven dependency:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
Directly in IntelliJ (Community edition):
Guava
Guava also provides conversion methods, but you will have to adapt your code:
https://github.com/google/guava/wiki/PrimitivesExplained#byte-conversion-methodsApache Common
Same for Apache Commons. It is a matter of taste.
http://commons.apache.org/proper/commons-codec/org.apache.commons.codec.binary.Hex(str.toCharArray())
No comments:
Post a Comment