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 "generator" which generates the finished jar file for them.
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
Path downloaded_temp_file = Paths.get("temp.jar");
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("easy_to_find_and_replace", "this_is_actually_the_user_input");
Files.write(Paths.get("no_longer_temp.jar"), new_file_content.getBytes(charset));
I do not get any error but the file goes from 19kb > 34kb, cannot be opened by winrar, when opened in notepad some strings can be extracted but nothing useful.
PK
��rR me/�� PK
��rR me/ruben/PK ��rR me/ruben/Main$1.class�U[WW���0$��تM-�p
J+ rmCJ�@�=$�08��3Jj�>��>��U�}�K�����>�/�W��O�}�p���Yk�e�=�|��ߙ������A5.`TcrWq*F0Y�)|��#
where me/ruben is the package, Main.class is the main class file.
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.
Any answer or reference to other source helps, thank you.