Search code examples
javajavac

IllegalArgumentException Invalid flag using the java compiler pragmatically


I'm trying to compile java files within my java application however they need to be compiled with additional classes which aren't in the class path. So in my code I put in the options like so:

Iterable options = Arrays.asList("-classpath \"/path/to/some/classes\"");

And then I compile like this:

JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, options, null, compilationUnits1);

The exact Error I am getting is this:

java.lang.IllegalArgumentException: invalid flag: -classpath "/path/to/some/classes"

Do I have to do it another way to add additional libraries to the classspath?


Solution

  • I'm pretty sure it has to be in two separate strings:

    Iterable<String> options = Arrays.asList("-classpath", "/path/to/some/classes");