• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Create "Virtual" Module?

 
Greenhorn
Posts: 2
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a project that uses Java 9 and generates some code during runtime based on data that is supplied to it for event handling. I would like to be able to put this generated code in it's own module that requires what it needs and only exports to what is allowed to call into it. I have been digging around in the sources with my IDE but I can not seem to find a way to create a module that is not blocked by some sort of non-public or non-exported method or class. For example, this could be the class that is generated:


With this being loaded by a ClassLoader that goes something like this:


How would I modify the class loading to load it into a module called "testmodule" that requires "java.base"(even though it is assumed, example) and exports to "moduleloader"?

I am well aware that hard coding the bytecode into the class like that is not a good idea, I will be using ASM for the actual project of mine.

(Sorry if the Java is not perfect, made it up for this post)
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to override the findClass(String className, String moduleName) method.
 
gudenau smith
Greenhorn
Posts: 2
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:I think you need to override the findClass(String className, String moduleName) method.



That is never called in my ClassLoader instance and it appears to be called by a different method that is passed a Module. This makes it appear as though I would need to create the module before the ClassLoader is invoked to load the class.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That makes sense. Keep us updated on your progress.
 
reply
    Bookmark Topic Watch Topic
  • New Topic