title: How do I edit a jar file from within my program
body: <p>Yes, I am aware that there are questions similar to mine, but I believe mine is slightly more specific. I have made a program but the people using it are unable to compile it either due to not having the jdk or not knowing how to (I have tried explaining in more detail but with no success), I have decided that the next best option is making a &quot;generator&quot; which generates the finished jar file for them.</p>
  <p>I do this by simply compiling a base jar file myself and uploading that to a server. The generator downloads my compiled jar file and replaces certain strings with the user's input. The main problem I am having is that I am unable to simply edit the downloaded file without messing with something, I have not been able to figure out how to do this, so far I have attempted reading the file's content replacing it, and rewriting it to a file, which is where my problem comes, since in the original there are multiple classes and packages, but when writing it to a file using Files.write() it completely ignores that. The code I have tried so far is</p>
  <pre><code>Path downloaded_temp_file = Paths.get(&quot;temp.jar&quot;);
  
  Charset charset = StandardCharsets.UTF_8;
  
  String temp_file_content = new String(Files.readAllBytes(downloaded_temp_file), charset);
  String new_file_content = temp_file_content.replaceAll(&quot;easy_to_find_and_replace&quot;, &quot;this_is_actually_the_user_input&quot;);
  Files.write(Paths.get(&quot;no_longer_temp.jar&quot;), new_file_content.getBytes(charset));
  </code></pre>
  <p>I do not get any error but the file goes from 19kb &gt; 34kb, cannot be opened by winrar, when opened in notepad some strings can be extracted but nothing useful.</p>
  <pre><code>PK
      ��rR              me/��  PK
      ��rR                  me/ruben/PK  ��rR               me/ruben/Main$1.class�U[WW���0$��تM-�p
   J+ rmCJ�@�=$�08��3Jj�&gt;��&gt;��U�}�K�����&gt;�/�W��O�}�p���Yk�e�=�|��ߙ������A5.`TcrWq*F0Y�)|��#
  </code></pre>
  <p>where me/ruben is the package, Main.class is the main class file.</p>
  <p>I have now told my story, in summary my question is:
  How do I replace a string within a jar file from another java program.</p>
  <p>Any answer or reference to other source helps, thank you.</p>