I need to update an xml file inside an executable jar file which is included into an ear file. Is there anyway to do it without using the java command line or the Unjar/edit the file/Re-jar operation. I think that it's complicated but is it possible (please note i'm using jdk5)?
Asked
Active
Viewed 926 times
1
-
I think jar util allows to add/update files inside jar – bichito Mar 16 '17 at 14:42
-
jar/war/ear files are effectively zip files with a different extension (and required to have a `META-INF` directory containing manifest and other stuff): AFAIK you should be able to edit them with any zip file utility – rrobby86 Mar 16 '17 at 14:54
-
If the jars are not signed you can just unzip them, change the files and zip again (they're basically zip files with a different extension). Btw, _executable_ jars inside an EAR???? – Thomas Mar 16 '17 at 14:55
-
3I don't think this is a good practice to update a JAR content. I suggest you to handle content that meant to be updated outside the JAR. So you can preserve the JAR integrety, the JAR will execute the same way in all cases. – Mickael Mar 16 '17 at 14:55
-
MickaëlB is right, this is generally not good practice. A user should normally be able to take a JAR file from any computer and run it on a different one with the same behavior. If you're saving stuff to a JAR file then depending on where they source the JAR file from, it might have different properties. – Naberhausj Mar 16 '17 at 15:11
-
thnks for all your answers, actually the file that i'm trying to modify contains an ejb configuration so it can't be placed outside the jar file. also, i choose this solution to avoid the creation of many jars. – Amdouni Mohamed Ali Mar 16 '17 at 15:32
-
Are you doing this at build time, or at runtime? As Mickaël points out, you should not attempt to modify .jar files in the runtime classpath. – VGR Mar 16 '17 at 16:00
-
at build time, not at runtime. actually i succeeded to update the file using commad lines (jar xf to extract the file and jar uf to update it). then the application worked perfectly. But, i'm looking for a solution without using commad lines that's the problem. – Amdouni Mohamed Ali Mar 16 '17 at 16:22
-
I found the solution at this post http://stackoverflow.com/questions/7548900/updating-jars-contents-from-code thnks for all your comments. – Amdouni Mohamed Ali Mar 16 '17 at 17:21