Dynamic Class Loading

Discussion in 'Plugin Development' started by Numenorean95, Oct 7, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Numenorean95

    I want to be able to dynamically load classes from an external jar file. Does anyone know how to do this?
     
  2. Offline

    ZerothAngel

    I'm kinda curious about this myself -- about what the "standard" or Bukkit way is. (Is there a Bukkit lib directory?) Anyway, I've been doing it two different ways:
    1. Use Maven shade to roll the external jar into the plugin jar. Maven isn't really a requirement to do this, but that's the build tool I use and the Maven shade plugin makes it really easy to do.
    2. Add a "Class-Path" entry to your plugin's jar's manifest. You should list the external jar relative to the plugins directory. And it doesn't hurt to specify multiple places:
      Code:
      Class-Path: lib/SomeJar.jar MyPlugin/SomeJar.jar ../lib/SomeJar.jar ../SomeJar.jar
      Then the server admin is responsible for putting the external jar in the proper place.
    If you really want to do it dynamically (you don't know where the jar is at runtime), you probably have to create your own classloader... google/stackoverflow have tons of info about that.
     
  3. Offline

    wwsean08

    you also could use fatjar to include them within your jar, but it'll be much bigger
     
  4. Offline

    Numenorean95

    Thanks but i do want to do it dynamically. I think i may have found somthing though on that site you posted up there ;)

    http://download.oracle.com/javase/tutorial/deployment/jar/jarclassloader.html
    I wasnt able to look through much, but it looks promising.
     
Thread Status:
Not open for further replies.

Share This Page