1

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?

Dean
  • 8,668
  • 17
  • 57
  • 86

2 Answers2

8

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

Iterable<String> options = Arrays.asList("-classpath", "/path/to/some/classes");
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
0

If you want to include more than one class paths like src, test or third-party-jars, etc. then separate them using a semicolon

List<String> opt = Arrays.asList("-cp",
                "/path/to/src;/path/to/test;path-to-ext-jarfile.jar");

Note: Don't add them as a separate element in a List, otherwise it again throws IllegalArgumentException Invalid flag.

Krishna Majgaonkar
  • 1,532
  • 14
  • 25