How to Run Another File

Discussion in 'Plugin Development' started by jay275475, Aug 26, 2013.

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


    Hello I made A Plugin But How can I make a command That would run a Java File in my plugin?
  2. Offline


    Do you mean an external jar (packaged in a file with .jar as the extension), or a class file (a .class), OR, a raw .java file (non-compiled)?
  3. Offline


    .class file
  4. Offline


    I'm assuming that you want to run a .class file that is imported or created at runtime, if so, you can use ClassLoader.
    2. try {
    3. // This is relative to your plugin location!!!
    4. URLClassLoader classLoader = new URLClassLoader(new URL[]{new URL("myclass.class")});
    5. // You can then create an instance of the class
    6. // It's recommended that you make myclass inherit an interface so you can actually do something with it first though
    7. Class<MyInterface> cl = (Class<MyInterface>) classLoader.loadClass("myclass");
    8. cl.doSomething();
    9. } catch (MalformedURLException e) {
    10. e.printStackTrace();
    11. e.printStackTrace();
    12. }

    A quick google gave me this impression.
  5. Offline


Thread Status:
Not open for further replies.

Share This Page