Code example for JarFile

Methods: close, getManifest

0
            throws IOException { 
        if (!jarFilePath.endsWith(".jar")) {
            throw new IllegalArgumentException("Jar file should have the extension .jar. " +
                                               jarFilePath + " is invalid");
        } 
        JarFile jarFile = new JarFile(jarFilePath);
        Manifest manifest = jarFile.getManifest();
        if (manifest == null) {
            throw new IllegalArgumentException(jarFilePath + " does not contain a MANIFEST.MF file");
        } 
        String fileSeparator = (File.separatorChar == '\\') ? "\\" : File.separator;
        String jarFileName = jarFilePath;
        if (jarFilePath.lastIndexOf(fileSeparator) != -1) {
            jarFileName = jarFilePath.substring(jarFilePath.lastIndexOf(fileSeparator) + 1);
        } 
        ArchiveManipulator archiveManipulator = null;
        String tempExtractedDir = null;
        try { 
            archiveManipulator = new ArchiveManipulator();
            tempExtractedDir = System.getProperty("basedir") + File.separator + "target" +
                               File.separator + jarFileName.substring(0, jarFileName.lastIndexOf('.'));
            new ArchiveExtractor().extractFile(jarFilePath, tempExtractedDir);
        } catch (Exception e) {
            log.error("Could not extract the file", e);
        } finally { 
            jarFile.close();
        } 
 
        String dynamicImports = manifest.getMainAttributes().getValue("DynamicImport-Package");
        if (dynamicImports != null) {
            manifest.getMainAttributes().putValue("DynamicImport-Package",