0

I am writing a java program that uses both pre-made and custom created methods from outside classes (classes outside the compiled .jar). Basically, at one point it asks you to select the file to use for the method. The file it asks you to choose is a java class file (.java because it will not be compiled yet). It then compiles and parses the file as if it were part of the program (.jar). Here is my question: is there any way to compile a file that is outside of the program .jar file and then parse it as if it were part of the program?

If it helps, here is some of the code that is included in the compiler/parser class inside the program, and also the code that should be included in the outside class:

Inside class:

public class CryptorLoader {
    public static void compile() {
    }
    public static void parse() {
    }
}

Outside class:

public class (name of custom class goes here) extends CryptorLoader() {
    public static void method() {
    }
}

I don't know if the extends CryptorLoader is necessary, but there will be code and variables in the inside class that will be used by the outside class. Any help would be greatly appreciated.

Thanks in advance,

Santiago

Santiago Benoit
  • 994
  • 1
  • 8
  • 22
  • 1
    Take a look at [this question](http://stackoverflow.com/q/1064259/2991525). cletus's answer seems to be what you're looking for. – fabian Jun 04 '14 at 21:37
  • You don't need to both compile and parse. Parsing is part of compilation. You need to be aware that the compiler is part of the JDK and is not present in the JRE, so your program won't work on 99% of Java installations. – user207421 Jun 04 '14 at 22:03
  • Would it work if I were to import the Compiler API into the lib folder? (I have a dedicated folder for libraries). – Santiago Benoit Jun 04 '14 at 22:09
  • If I were to import the compiler API into my project lib folder, where can I find the JDK compiler API? – Santiago Benoit Jun 04 '14 at 22:28

0 Answers0