-2

So again this is one of my Java minecraft plugins, and I'm trying to make a command that runs a specific code that will run on the server, so what I stumbled on is

                    String code = "package code; \n"
                            + "public class MyClass { \n"
                            + "    public void myMethod(){ \n"
                            + "        " + args[1] + "\n"
                            + "    } \n"
                            + "}";
                    Dir.save(code, new File(getDataFolder(), "MyClass.java"));

so this is my code it will try to save the string in a file, btw please tell me if this string will work as it is meant to be. then what I want to do In here is that I want to compile this file and run it in my server, its like an external file out side the program, so how do I do it. How do I run this MyClass.java with the libraries of the server's codes, because I want the code to run with what the server offers from classes!

hamoodrex
  • 35
  • 7

1 Answers1

0

this is my code it will try to save the string in a file, btw please tell me if this string will work as it is meant to be

This part of the question could have been ommitted. You may try to run that code snippet and check if the file will be saved as you want it to; if it is, then the answer is yes. Otherwise, it is no.


It is possible to dinamically compile and execute code in the server. To achieve this effect, you may want to take a look at:

Community
  • 1
  • 1
Bruno Toffolo
  • 1,504
  • 19
  • 24
  • You still don't get it I want to run the MyClass.java as in external file, I mean like if it was in C:\Program Files\MyClass.java or tell me if I can load the MyClass.java file as an object then compile and run with the server's libraries – hamoodrex Oct 31 '15 at 09:36
  • 1
    @hamoodrex If you want people to understand what you're asking, word your question better. – gogobebe2 Oct 31 '15 at 23:38