The Problem:
While migrating a multi-module project to Java 17, an issue arises when trying to provide module dependencies in module-info.java files. Specifically, the javax.validation module is not found, despite adding various "requires" lines in module-info.java. The project uses a maven dependency for javax.validation, but it’s unclear how to obtain the corresponding Java module for this dependency.
The Solutions:
Solution 1: Use jakarta.validation or java.validation
javax.validation is not available as a Java module. You can use either `jakarta.validation` or `java.validation` instead. The latest version of the Jakarta Validation API is 3.0.2. You can add the following dependency to your pom.xml file:
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
You can also use the java.validation
module. This module is part of the Java Development Kit (JDK) and provides a limited subset of the Jakarta Validation API. To use this module, you can add the following line to your module-info.java file:
requires java.validation;
You can find the Jakarta Validation specification here. 3.0 is current, while 3.1 is under development. Hibernate Validator is the sole implementation for 3.0 & 3.1.
Q&A
Where do I get the java module for the javax.validation dependency?
javax.validation is not available as a Java module.
What are the options to use instead of javax.validation?
java.validation or jakarta.validation.
What is the latest version of Jakarta Validation API?
3.0.2.
Video Explanation:
The following video, titled "Migrating to Java 9 Modules with ModiTect by Gunnar Morling ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
runtime images containing just the modules an application needs, the advantages of the module system are manyfold. How to migrate existing ...
The following video, titled "Migrating to Java 9 Modules with ModiTect by Gunnar Morling ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
runtime images containing just the modules an application needs, the advantages of the module system are manyfold. How to migrate existing ...