public static boolean addFilesToExistingJar ( File jarFile , String basePathWithinJar , Map < String , File > files , ActionOnConflict action ) throws IOException { // get a temp file File tempFile = FileHelper . createTempFile ( jarFile . getName ( ) , null ) ; boolean renamed = jarFile . renameTo ( tempFile ) ; if ( ! renamed ) { throw new RuntimeException ( "[ArchiveHelper] {addFilesToExistingJar} " + "Could not rename the file " + jarFile . getAbsolutePath ( ) + " to " + tempFile . getAbsolutePath ( ) ) ; } ZipInputStream jarInput = new ZipInputStream ( new FileInputStream ( tempFile ) ) ; ZipOutputStream jarOutput = new ZipOutputStream ( new FileOutputStream ( jarFile ) ) ; try { switch ( action ) { case OVERWRITE : overwriteFiles ( jarInput , jarOutput , basePathWithinJar , files ) ; break ; case CONFLICT : conflictFiles ( jarInput , jarOutput , basePathWithinJar , files ) ; break ; default : // This should never happen with validation of action taking place in WarDriver class throw new IOException ( "An invalid ActionOnConflict action was received" ) ; } } finally { if ( ! tempFile . delete ( ) ) log . warn ( "Could not delete temp file " + tempFile ) ; } return true ; }
Adds a file or files to a jar file replacing the original one