0

We want to give our users the ability to write small Java methods that we call when our library runs. These users don't have the JDK installed and wouldn't know how to do that. But they do have Java installed and are running our Java library.

Is there a way we can ship some minimal Java compiler with our library?

David Thielen
  • 28,723
  • 34
  • 119
  • 193

2 Answers2

4

The javac compiler has a programmatic interface (this is used by jshell, among other things) and lives in the modules java.compiler and jdk.compiler in Java 9 and later. Express a dependency on these modules and build a runtime with jlink.

Brian Goetz
  • 90,105
  • 23
  • 150
  • 161
0

You can isolate some of the executables by trial and error and I have done this for the jps and jcmd tool for process checking for my application.

I've just quickly tried this for javac and managed to get it compiling correctly but hopefully this isn't using some of my system variables.

You need a folder structure like

bin
-> javac.exe
-> jli.dll

lib
-> tools.jar

Place your code into the bin folder and run javac

Baring in mind what you will need for javac to run is operating system dependant and this was tested on Windows. You might need some extra files for other operating systems like Linux as this was one of the problems I encountered.

jjmcc
  • 795
  • 2
  • 11
  • 27