0

I have a multi module maven project structure like this:

parent A B C

(so modules A, B and C are my modules "inside" the parent).

A is not modularized, while B and C are (A just contains a very small main method). Module A depends on B and C, and B depends on C.

It all works just fine -- all the module dependencies, module-info files etc are working correctly.

But I now have a problem. B compiles some Java code on the fly in memory using the JavaCompiler API. An example piece of code might be:

package whatever;
import C.X;
...

So the compiled code is using class X in module C.

All the generated code used to run fine before I modularized my projects. B contains a custom JavaFileManager extending ForwardingJavaFileManager and some custom SimpleJavaFileObjects.

When I compile the above code now the compiler says that it cannot find A.X.

I presume I have to configure my custom JavaFileManager to handle modules somehow, but I have not been able to get this to work.

There are some posts on stackoverflow about the JavaCompiler API but almost all are about what worked before Java modules were introduced.

So I was wondering if anyone could point me to a discussion, or even some code, that shows how to handle the above issue correctly.

thanks

gym
  • 1
  • 1
  • I think the issue lies in your imports and module exports. Also I think this might assist you:[calling a non module class from a module class](https://stackoverflow.com/questions/48365299/calling-a-non-module-class-from-a-module-class-in-java-9). Since A is not a module it may not be recognized by other classes, check the first answer. – Alias Cartellano Sep 14 '21 at 17:09
  • I have also modularized A, and nothing changes. All the code runs right up the point where the runtime code is generated and imports C.X. – gym Sep 14 '21 at 22:03
  • Can I see your code? – Alias Cartellano Sep 14 '21 at 22:19
  • I solved my own problem. Nothing wrong with my code -- essentially the Java 8 solutions work fine even in the modular setting. The issue was with Maven setting the wrong class path. – gym Sep 25 '21 at 21:44

0 Answers0