How to copy a signed jar file?
I have a jar file that is singed. I only need to update a text file inside this .jar file every few minutes by replacing it with another file from outside (same name but different size and contents). So I'm just copying the files from the old jar to a newly created one, then delete the old one and rename the new jar file to the name of the old one. It works fine when it's not signed - I don't get any errors. But when I'm trying to do this over a signed .jar - the Java VM throws a security exception bound to the file that has been 'replaced' (complaining that the "SHA1" (checksum) didn't pass on the replaced file.). If someone knows if there's a way to bypass/sign it programmatically please let me know
Here's my code:
......
File theJar =new File( sFilePath );
File jarFileDir =new File( theJar.getParent() );
String sFileName = theJar.getName();
String sNewFileName ="new_file.jar";
String sNewFilePath = jarFileDir.getPath() + Log.slash + sNewFileName;
try{
JarInputStream jarIn =new JarInputStream(new FileInputStream( theJar ) );
Manifest manifest = jarIn.getManifest();
JarOutputStream jarOut =new JarOutputStream (new FileOutputStream ( sNewFilePath ), manifest );
byte[] bytes =newbyte [ 4096 ] ;
JarEntry entry =null;
while( ( entry = jarIn.getNextJarEntry() ) !=null ){
String sEntryName = entry.getName();
boolean isDatabase = sEntryName.indexOf( sDatabaseName ) > -1;
if( isDatabase ){
continue;
}else{
jarOut.putNextEntry( entry );
}
int iRead = 0;
while( (iRead = jarIn.read( bytes )) != -1 ){
jarOut.write ( bytes, 0, iRead );
}
jarOut.closeEntry();
}
JarEntry dbEntry =new JarEntry( sDatabaseName );
File dbFile =new File( jarFileDir.getPath() + Log.slash + sDatabaseName );
bytes = Log.getFileInBytes( dbFile.getPath() );
jarOut.putNextEntry( dbEntry );
jarOut.write( bytes, 0, bytes.length );
jarOut.closeEntry();
jarOut.flush();
jarOut.close();
File f1 =new File( sFilePath );
f1.delete();
File f2 =new File( sNewFilePath );
f2.renameTo( f1 );
dbFile.delete();
}catch( Exception exc ){
exc.printStackTrace();
}

