use of com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile in project Payara by payara.
the class ApplicationFactory method getApplicationName.
/**
* @param jarFile the .ear file
* @return the application name from an application .ear file
*/
public String getApplicationName(File jarFile) throws IOException {
if (!jarFile.exists()) {
throw new IOException(localStrings.getLocalString("enterprise.deployment.exceptionjarfiledoesn'texist", "{0} does not exist", new Object[] { jarFile }));
}
/*
*Add finally clause containing explicit close of jar file.
*/
JarFile jar = null;
try {
jar = new JarFile(jarFile);
ApplicationDeploymentDescriptorFile node = new ApplicationDeploymentDescriptorFile();
node.setXMLValidation(false);
ZipEntry deploymentEntry = jar.getEntry(node.getDeploymentDescriptorPath());
if (deploymentEntry != null) {
try {
Application application = (Application) node.read(jar.getInputStream(deploymentEntry));
return application.getDisplayName();
} catch (Exception pe) {
logger.log(Level.WARNING, "Error occurred", pe);
}
}
} finally {
if (jar != null) {
jar.close();
}
}
return null;
}
Aggregations