in src/main/java/org/apache/maven/plugins/ear/EarMojo.java [302:391]
public void execute() throws MojoExecutionException, MojoFailureException {
// Initializes ear modules
super.execute();
File earFile = getEarFile(outputDirectory, finalName, classifier);
MavenArchiver archiver = new EarMavenArchiver(getModules());
File ddFile = new File(getWorkDirectory(), APPLICATION_XML_URI);
JarArchiver theArchiver;
if (ddFile.exists()) {
earArchiver.setAppxml(ddFile);
theArchiver = earArchiver;
} else {
// current Plexus EarArchiver does not support application.xml-less JavaEE 5+ case
// => fallback to Plexus Jar archiver
theArchiver = jarArchiver;
}
getLog().debug("Ear archiver implementation [" + theArchiver.getClass().getName() + "]");
archiver.setArchiver(theArchiver);
archiver.setOutputFile(earFile);
archiver.setCreatedBy("Maven EAR Plugin", "org.apache.maven.plugins", "maven-ear-plugin");
// configure for Reproducible Builds based on outputTimestamp value
archiver.configureReproducibleBuild(outputTimestamp);
final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
final Collection<String> outdatedResources = initOutdatedResources();
// Initializes unpack types
List<String> unpackTypesList = createUnpackList();
// Copy modules
copyModules(javaEEVersion, unpackTypesList, outdatedResources);
// Copy source files
try {
File earSourceDir = earSourceDirectory;
if (earSourceDir.exists()) {
getLog().info("Copy ear sources to " + getWorkDirectory().getAbsolutePath());
String[] fileNames = getEarFiles(earSourceDir);
for (String fileName : fileNames) {
copyFile(new File(earSourceDir, fileName), new File(getWorkDirectory(), fileName));
outdatedResources.remove(Paths.get(fileName).toString());
}
}
if (applicationXml != null) {
// rename to application.xml
getLog().info("Including custom application.xml[" + applicationXml + "]");
File metaInfDir = new File(getWorkDirectory(), META_INF);
copyFile(applicationXml, new File(metaInfDir, "/application.xml"));
outdatedResources.remove(Paths.get("META-INF/application.xml").toString());
}
} catch (IOException e) {
throw new MojoExecutionException("Error copying EAR sources", e);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("Error filtering EAR sources", e);
}
// Check if deployment descriptor is there
if (!ddFile.exists() && (javaEEVersion.lt(JavaEEVersion.FIVE))) {
throw new MojoExecutionException("Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist.");
}
// no need to check timestamp for descriptors: removing if outdated does not really make sense
outdatedResources.remove(Paths.get(APPLICATION_XML_URI).toString());
if (getJbossConfiguration() != null) {
outdatedResources.remove(Paths.get("META-INF/jboss-app.xml").toString());
}
deleteOutdatedResources(outdatedResources);
try {
getLog().debug("Excluding " + Arrays.asList(getPackagingExcludes()) + " from the generated EAR.");
getLog().debug("Including " + Arrays.asList(getPackagingIncludes()) + " in the generated EAR.");
archiver.getArchiver().addDirectory(getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes());
archiver.createArchive(session, getProject(), archive);
} catch (ManifestException | IOException | DependencyResolutionRequiredException e) {
throw new MojoExecutionException("Error assembling EAR", e);
}
if (classifier != null) {
projectHelper.attachArtifact(getProject(), "ear", classifier, earFile);
} else {
getProject().getArtifact().setFile(earFile);
}
}