Dynamic Maven Artifact using ASM - Module not found
I generate a maven artifact dynamicly. In order to modularize the Artifact I need to generate a module-info.class. This is my code to generate the bytecode:
Unfortunately maven is unhappy with the module-info.class. Message is:
15 Replies
⌛ This post has been reserved for your question.
Hey @Peter Rader! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Can you elaborate on what you mean with creating an artifact dynamically? When do you create it? How do you add the created artifact to the build? Can you run the (failing) Maven build with
-X and show the output? Can you show the final module-info.class?
btw the Class-File API exists as well, just sayingOh just create a jar-file having the bytecodes that has been generated from the buildModuleClass-call in the root-file named "module-info.class". The rest of the jar could remain empty. Then install the jar using
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
I create the jar on demand.so the JAR is created in a distinct Maven build
Can you run
jar tf <jarfile>.jar on the JAR in the local Maven repo?
And then extract it and run javap module-info.classWhat exact files are in the repo for that version?
and what is the output of the failing Maven build with
-X?
btw you censored the package name here but not in the jar tf output if you want to edit itBy the way, other module-info.class show this structure in eclipse:

I may miss the "module packages:" scope....
hm?
oh right
As you can see in the class-file-editor, the module-name is mentioned twice. In the first and last line.
Hm, the ModuleVisitor have a method "visitPackage". I think I need to call it.
I dont know how to write a unit test for that!
https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.7.26
It's just a class file attribute
The ModulePackages attribute is a variable-length attribute in the attributes table of a ClassFile structure (§4.1). The ModulePackages attribute indicates all the packages of a module that are exported or opened by the Module attribute, as well as all the packages of the service implementations recorded in the Module attribute. The ModulePackages attribute may also indicate packages in the module that are neither exported nor opened nor contain service implementations. There may be at most one ModulePackages attribute in the attributes table of a ClassFile structure.but first try using it with the
javac/java command line and see whether that allows using your module
and then check the Maven build with the -X argument which includes more information on the compilation
I wouldn't be surprised if a missing POM in the local repo causes the issuemodules have no package-declaration. Since the ModuleVisitor have such method, I think it is reused for the "module packages:" scope.
they have a list of
opened and exported packages
So in your case, it would include de.xxx
btw you can also use javap -v
Yeeees, solved! The correct implementation is:
Works like a charm!
Post Closed
This post has been closed by <@574922348642172929>.