private void processWeaving(ClassLoader classLoader) throws MojoExecutionException { if (!source.exists()) { throw new MojoExecutionException("Source directory " + source + " does not exist"); } try { if (prefix != null) { getLog().info("Using package prefix '" + prefix + "'"); } final URL[] classPath = getClassPath(); getLog().debug("Scanning class-path: " + Arrays.toString(classPath)); final AnnotationDB db = new AnnotationDB(); db.setIgnoredPackages(getIgnoredPackages()); db.scanArchives(classPath); final Set<String> entityClasses = findEntities(db); getLog().info("Entities found : " + entityClasses.size()); final File targetFile = new File(this.target + "/META-INF/persistence.xml"); getLog().info("Target file: " + targetFile); final String name = project.getArtifactId(); final Document doc = targetFile.exists() ? PersistenceXmlHelper.parseXml(targetFile) : PersistenceXmlHelper.createXml(name); checkExisting(targetFile, classLoader, doc, entityClasses); PersistenceXmlHelper.appendClasses(doc, entityClasses); PersistenceXmlHelper.outputXml(doc, targetFile); final StaticWeaveProcessor weaveProcessor = new StaticWeaveProcessor(source, target); weaveProcessor.setClassLoader(classLoader); weaveProcessor.setLog(new PrintWriter(System.out)); weaveProcessor.setLogLevel(getLogLevel()); weaveProcessor.performWeaving(); } catch (URISyntaxException | IOException e) { throw new MojoExecutionException("Error", e); } }