0

I am setting up a .jar file loader, and I want to modify a .yml File in the .jar File before I use it in a method like this. Bukkit().getPluginManager().loadPlugin(File file); If i understand it correctly, i have also have to save the changes.

I don't have the knowledge of how to do this, because I have never used files in a way like this before in Java 8. If there is somebody out, I would be very happy

Here the method where I load the jar Files, and then the place, where I want to modify and save it

for (final File file : folder.listFiles()) {// Get all files in the folder
        if (!file.isDirectory()) {// Only use the file, if it is a regular file
            try {
                if (FileManager.isJarFile(file)) {
                    // found a jar file
                    System.out.println("Found jarfile with possible yml.file in it: " + file.getName());

                    /*
                     * 
                     * Here it should modify the .jar file like above, bevore it gets loaded
                     * 
                     */

                }
            } catch (IOException e) {
                // Didn't found that jar file, can ignore it
            }
        }
    }

Short: So what should the method do? It should load the jar file, load a .yml file in it, modify the file, and then save the changes in the .jar file again.

sulox32
  • 419
  • 3
  • 19
Gebes
  • 312
  • 2
  • 9
  • Honestly, that sounds like a strange idea. What is the point of handing out JAR files, when you then have to manipulate their content? Can't you just make all things that need "configuration" available in other ways? – GhostCat May 21 '19 at 13:56
  • 1
    The point is: I am working with the Spigot API. The API has a plugin system. In the .yml file i want to edit some settings, which can't be changed in the API, so the only way to edit those settings is to edit the .yml file in the .jar. This Code, above should load the jar file, edit the yml file and then save it. Then i can tell the API to load the modified .jar file – Gebes May 21 '19 at 14:01
  • @GhostCat Can I handle .jar file like a Zip File? Then I just could use this code in a modified way https://stackoverflow.com/questions/11502260/modifying-a-text-file-in-a-zip-archive-in-java – Gebes May 21 '19 at 14:06
  • A JAR file is basically just that: a ZIPped file. But honestly, I lack the details on how you can "exchange" one for the other programmatically. In the end: the fun lies in finding that out. So just *try* things, and see where your experiments lead you ;-) – GhostCat May 21 '19 at 14:08

0 Answers0