PaperMC / Paperclip

Bootstrap utility and launcher for the Paper Minecraft server
MIT License
120 stars 51 forks source link

Fails to start when jar is located in subdirectory #13

Closed jhead closed 7 years ago

jhead commented 7 years ago

Problem

When launching Paperclip from the server directory while the Paperclip jar is stored in a subdirectory, downloads succeed but it then fails to find the cache folder.

Logs

[16:04:09] Error running patched jar
[16:04:09] java.lang.ClassNotFoundException: org.bukkit.craftbukkit.Main
[16:04:09] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[16:04:09] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[16:04:09] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
[16:04:09] at java.lang.Class.forName0(Native Method)
[16:04:09] at java.lang.Class.forName(Class.java:348)

Directory listing after launch

$ find .
.
./cache
./cache/mojang_1.12.2.jar
./cache/patched_1.12.2.jar
./subdir
./subdir/paperclip.jar

Steps to reproduce

  1. Create directory
  2. Download Paperclip to directory
  3. cd to parent directory
  4. Run Paperclip: java -jar subdir/paperclip.jar

Workaround

Moving the cache dir into the subdir causes Paperclip to re-download the files, but then launches properly. Creating a symlink works as well.

Proposed Solution

Ideally, Paperclip would look for the cache dir in the same place that it downloaded it, not in relation to the Paperclip jar itself.

dkabot commented 7 years ago

This issue appears to only occur as of 1.12.2. On the latest 1.12.1 build 1204 and earlier, this worked as expected, launching out of the cache folder even when that is not ./cache relative to the PaperClip JAR.

dkabot commented 7 years ago

I believe I found the cause of this issue.

The old version read the path of the patched JAR to a URL, then added that to the ClassLoader before invoking the main class: https://github.com/PaperMC/Paperclip/blob/6dcb3241ca8e69fb8209e54fea507425c508915e/src/main/java/com/destroystokyo/paperclip/Paperclip.java#L265

The current build instead moves that to a separate class, and in the process, adding to the ClassLoader was dropped: https://github.com/PaperMC/Paperclip/blob/c56226165db05fbd50f4951bda32452330f160e2/java8/src/main/java/com/destroystokyo/paperclip/Utils.java#L55