Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

Setting Java classpath with wildchar when programmatically compiling the class file

user-wy8d3Jun 12 2023

I have a program that compiles a Java class.

JavaCompiler.CompilationTask compilationTask = compiler.getTask(null, fileManager, diagListener, compilerOptions, null, Arrays.asList(compilationUnit));
compilationTask.call;

In compilerOptions, classpath is being set with -classpath

I need to modify this by adding wildchar in the classpath so that it will add all jar files from the directory.

I tried the following values for being used for the -classpath flag, but all fails.

  1. "one.jar:two.jar:/data/third_party/*:"
  2. "one.jar:two.jar:/data/third_party/*"
  3. "\"one.jar:two.jar:/data/third_party/*\""

Is there a way to make this work?

Edit: This is not about the options we set from the command line. I am aware of existing questions on that.

Version used is Java8

Comments
Post Details
Added on Jun 12 2023
1 comment
352 views