Class not found with JavaCompiler on Debian Linux and Tomcat 7

I have an app that compiles some Java code using JavaCompiler. It uses a custom classpath for compilation that I pass to Java compiler using the -classpath parameter.

List<String> optionList = new ArrayList<String>();
optionList.addAll(Arrays.asList("-classpath", "c:/some/dir;c:/another/dir"));

JavaCompiler.CompilationTask task = compiler.getTask(out, fm, diagnostics, optionList , null, fos);


The code works fine on Windows with Tomcat 7, however, when I try to run in on Debian, none of the classes that should be found on the classpath are found and the compilation fails.
graham on 08-01-2014 08:35
The reason why the code failed is that the classpath I used was created from two directories separated by a semi-colon.

However, semi-colon is used as classpath element separator only on Windows. On Unix, you need to use a colon. So the relevant code would look like this for Linux:
optionList.addAll(Arrays.asList("-classpath", "/opt/some/dir:/opt/another/dir"));
graham on 08-01-2014 08:38

Post an answer

Do you have a solution to this problem, or want to comment on it? Other users will appreciate your help!
Your answer or comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems