I use graalvm features,my project need to generate dynamics class,so i need to register it,originally ,I can implements RuntimeHintsRegistrar,but since my class is dynamics generated,i want to register inside my business code,any soultion can provider for me? thanks a lot
original method:
class xx implements RuntimeHintsRegistrar{
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.reflection().registerType(Trace1.class, hint ->
hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
}
}
Comment From: bclozel
What do you mean by dynamically generated? Can you share a code snippet showing how this class is generated? Can you also explain what's known at build time and what is only known at runtime?
Comment From: zrwsmd
i use mybatis generator api generator class,which is similar to mybatis generator plugin generating classs
Comment From: bclozel
I think this needs to be run at build time - we can't generate random types at runtime without knowing anything in advance about them. This should be done during the AOT phase, there are dedicated contracts for that.
Comment From: zrwsmd
can i use javassit or asm to change byte code to achieve it?
Comment From: bclozel
There is no bytecode at runtime in a native image.
Comment From: zrwsmd
use build time compiler tool like maven-aspectj-plugin can achieve it?