Search code examples
javajarcompilation.class-file

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


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.

  1. What API must I use to create the .class file?
  2. Are there any other solutions to create a .jar from the source code?

Solution

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

    There is this excellent tutorial that can walk you through.