ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) classLoader = getClass().getClassLoader();
classLoader = new URLClassLoader(new URL[]{new File(directory).toURI().toURL()}, classLoader);
jaxbGenerator.setClassLoader(classLoader);
jaxbGenerator.generate();
} catch (JAXBException e) {
throw new MojoExecutionException("Error generating JaxB parser: " + e.getMessage(), e);
} catch (MalformedURLException e) {
throw new MojoExecutionException("Invalid build outputDirectory " + project.getBuild().getOutputDirectory());
}