9

I have 3 jar of jackson library

  1. jackson-core-2.8.10.jar
  2. jackson-annotations-2.8.0.jar
  3. jackson-databind-2.8.10.jar

I created module-info.java for both core and annotation successfully and converted them to Named maodule using jdeps.

for databind , I tried following command:

jdeps --generate-module-info . --module-path %JAVA_HOME%\jomds;jackson.core;jackson.annotations existingmods\jackson-databind-2.8.10.jar

Now following error is occuring :

Missing dependence: .\jackson.databind\module-info.java not generated
Error: missing dependencies
   com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonCreator       not found
   com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonCreator$Mode  not found
   com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonFormat        not found
   com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonFormat$Value  not found
   com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonIgnoreProperties not found
   com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonIgnoreProperties$Value not found.

How can I generate module-info.java for jackson-databind ?

optional
  • 3,260
  • 5
  • 26
  • 47
  • 1
    Possible duplicate of [is-there-a-way-to-add-maven-dependencies-while-using-the-maven-jlink-plugin](https://stackoverflow.com/questions/47103221/is-there-a-way-to-add-maven-dependencies-while-using-the-maven-jlink-plugin)? Considering maven as a framework in the other question isn't the cause of the failure. – Naman Dec 09 '17 at 12:20

2 Answers2

22

The short answer is that, yes, you'll have to convert the libraries to explicit modules.

The jlink tool is intended to provide a trimmed binary image that has only the required modules. The issue is that automatic modules have access to the classpath (aka the unnamed module) which can read all JDK modules. So nothing would be trimmed.

This thread states this as well, with a link to a YouTube video.

This example converts commons-lang3-3.5.jar to an explict module for a jlink demo.

Edit: to be more specific, here is an example script that converts, in order, jackson-core, jackson-annotations, and jackson-databind legacy jars to modular jars.

The idea is:

  • run jdeps --generate-module-info on the legacy jar
  • unzip the legacy jar into a folder, add module-info.java from above, re-compile, and re-zip

The trick is that modular jars with dependencies will require those dependencies as command-line parameters. For example, here is jackson-databind (abstracted somewhat):

# here, jackson-core and jackson-annotations have been built
# jackson-databind 

jdeps --module-path $ROOT_DIR/modules \
--add-modules jackson.annotations,jackson.core \
--generate-module-info work $JACKSON_DATABIND_JAR

javac --module-path $ROOT_DIR/modules \
--add-modules jackson.annotations,jackson.core \
-d $ROOT_DIR/classes module-info.java
Michael Easter
  • 23,733
  • 7
  • 76
  • 107
  • 2
    I have updated the answer with a link to a GitHub solution that converts all three jars. – Michael Easter Dec 09 '17 at 17:27
  • 2
    Although I made all the jars moduler but still jackson.databind is not reading jackson.annotation module while creating module-info.java using jdeps. – optional Dec 10 '17 at 03:32
  • I am manually adding requires transitive jackson.annotations to module-info.java for jackson.databind – optional Dec 10 '17 at 03:41
  • 1
    Recompiling is unnecessary. You can [inject](https://stackoverflow.com/questions/47222226/how-to-inject-module-declaration-into-jar) a module declaration into the JAR. – ZhekaKozlov Jun 14 '20 at 14:18
3

The accepted answer describes to create Java 9 module info for libraries that do not provide it (they are treated as automatic modules).

Jackson, starting with version 2.10.0, actually provides Java 9 module info.

Alex Suzuki
  • 1,083
  • 10
  • 18