Hi, I am having an exception in the “vaadin-maven-plugin”. I made a configuration in order to use a custom Jackson object mapper that works fine when I run the project from IDE, but it is causing a “java.lang.ClassNotFoundException” when I try to generate the production package.
This is the plugin configuration with the jackson mapper:
Caused by: java.lang.ClassNotFoundException: com.example.MyObjectMapperFactory
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass (ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:239)
I cannot figure out how to solve the ClassNotFoundException, any idea is really appreciated.
Yes, its a class in the project compiled in ./target/classes directory. I think the same, the pluggin is not seeing those clases. What are my options? Is there any parameter I can add in pom.xml or in the command line to pass the path to the comiled class or something similar so the pluggin can load it?
Thank you for your comments. Do you mean creating a new maven dependency/artifac with the MyObjectMapperFactory inside? I wonder now if there is a maven pluggin that allows me to run the vaadin-maven-plugin with an altered classpath. :/
Yes, I mean create a new independent maven module/project with the customized class.
I’m not aware of any workaround to augment the plugin class loader by configuring the POM file, other than adding entries in the <dependencies> section of the plugin configuration.
Yes, that will work. However, because chances of modiffing the mapper are high I ended up modifing the mojo build pluggin so I added a “includeInRealmPaths” property so I can add extra paths to the ClassRealm. Here is the code in case helps anybody.
@Parameter(property = "includeInRealmPaths")
private List<String> includeInRealmPaths;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().debug("Starting execution of mojo BuildFrontendMojo");
final PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
if (includeInRealmPaths != null && !includeInRealmPaths.isEmpty()) {
getLog().debug("Inclusions in realm detected");
for (String path : includeInRealmPaths) {
getLog().debug("Including '" + path + "'");
final ClassRealm classRealm = pluginDescriptor.getClassRealm();
try {
classRealm.addURL(new File(path).toURI().toURL());
} catch (MalformedURLException e) {
getLog().error("I could not include in realm" + e);
e.printStackTrace();
}
}
} else {
getLog().debug("No inclusions in realm requested");
}
super.execute();
}
}
Good work!
Do you mind creating a feature request issue on the Hilla repository explaining the problem and posting your solution?
Hilla team may be interested in improving the official plugin.