1.16.5 Plugin multiple java version support

Discussion in 'Spigot Plugin Development' started by UmbralPhoenix, Feb 16, 2021.

  1. Hey, I have a question. I have a plugin that only works for Java 8, but have been asked to make it support Java 11. Thing is, I don't want it to not support Java 8 anymore. I've seen plugins online that say to "Please use Java 8 or later!", which signals they have multiple java version supports. So my question.

    How do I make my plugin support Java 8 and Java 11? Is it even possible?

    Thanks.
     
  2. There is no such thing like a plugin being designed to a specific Java version.
    They should work, for instance, from Java 8 up to Java 15.

    Using functionalities such as Lambda oblige you to use at least Java 8, the version at which it was first implemented. But as far as I am aware, there is no specific reason for why a Java 8 plugin would not work in newer versions. The only thing that comes to my mind is the missing of certain unsafe reflection libraries that existed in earlier versions.
     
  3. Java is typically forwards-compatible. As @Cookiewhite pointed out Lambdas will work in anything >= Java 8 you just can't run a plugin that has been compiled with Java 11 on Java 8, it is Java's way of preventing errors from occuring at runtime.

    As for it's forwards compatiblity, it varies a little. Java will never/rarely remove methods but deprecate them and this can be seen as early as JDK 1.1.

    Your best bet for supporting Java 8-11(+) is just be compling and developing against Java 8 that way you have the compatibilty of all future Java versions unless major changes are made.

    Side Note: I would just like to add that Java 8 is slightly old now but Java 9 & 10 didn't offer anything that was worth upgrading over and is why a lot of servers still run Java 8 and as a result of this, that is why most developers use Java 8 to develop with.
     
  4. I compile against Java 8 but then my plugin doesn't work for Java 11. That confuses me. Do you know what to do then as it doesn't work?
     
  5. Are you encountering any errors?
     
  6. Please log what error occurs.
     
  7. The thing is, I was told that it didn't work from someone else and I saw the errors but can't find them again. I want to recreate the error but don't know how to switch the java version. How do you switch a server from Java 8 to Java 11 if I am manually hosting it? Searched online and no answer for manual hosting.
     
  8. Install the desired version and point out to the java file manually in your start.bat or start.sh.

    Example:
    Code (Text):
    /home/user/.jdks/corretto-15.0.1/bin/java -Xms512M -Xmx1024M ...
    Code (Text):
    "C:\Program Files\Amazon Corretto\jdk11.0.9_12\bin\java" -Xms256M -Xmx512M ...
     
  9. So you gave me two texts, where do I put them? I'm on a mac right now so I have a start.command, and in there this is the text.

    Code (Text):
    #!/bin/bash
    cd "$(dirname "$0")"
    exec java -Xms1G -Xmx1G -jar spigot.jar nogui
    So then what do I change it to?
     
  10. Hahaha didn't expect Mac. Pretty sure you have to put the path where the word 'java' is (I pointed it out with bold): exec java -Xms1G
     
  11. So do I put the JDK 11 right where java is bolded or what?
     
  12. Yes, in my case it would be something like: exec /home/user/.jdks/corretto-15.0.1/bin/java -Xms1G -Xmx1G -jar spigot.jar nogui
     
  13. This would only happen if you used Java 8 exclusive features, which don't exist. Make sure you are compiling for the correct version of Java.