How to create a runnable jar file from source code programmatically?

.class-file, compilation, jar, java

Solution

In order to do that, you can use the Java Compiler API.

There is this excellent tutorial that can walk you through.

Problem

I need to create runnable `.jar` file programmatically from a string. My decision is to create a `.class` file from string and add it to the `.jar` using JarOutputStream. - What API must I use to create the `.class` file? - Are there any other solutions to create a `.jar` from the source code?

Original source