how to use remote jars in classpath for javax.tools.JavaCompiler

263 Views Asked by At

I'm using JavaCompiler to compile .java code.

It works for me while running the class compiled using URLClassLoader to load remote jars. But not work while compiling.

Tried to use options like

options.addAll(Arrays.asList("-classpath", "https://example.com/example.jar"));

Also tried to use customized JavaFileManager with URLClassLoader.

None of them works.

1

There are 1 best solutions below

1
On

try below commands, and replace the .jar file with your external .jar file... into the command prompt or terminal.

$ javac -cp ".:./jars/common.jar" helloworld.java $ java -cp ".:./jars/common.jar" helloworld