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?

6
  • The answer is most likely “yes, this is a way.” The next question you should ask is “who knows a way to do this.” Commented Mar 2, 2018 at 22:12
  • I know that you can ship some things such as jps and jcmd, but I haven't tried the compiler Commented Mar 2, 2018 at 22:12
  • Cannot you make this some kind of API Service call ? Commented Mar 2, 2018 at 22:15
  • 5
    They wouldn't know how to install the JDK, but you expect them to know how to write their own methods? Commented Mar 2, 2018 at 22:17
  • 2
    Installing the JDK takes 8 clicks. Commented Mar 2, 2018 at 22:18

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.