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

后端 未结 2 1388
旧巷少年郎
旧巷少年郎 2021-01-12 06:34

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 .ja

2条回答
  •  醉酒成梦
    2021-01-12 07:10

    To compile code, you need a compiler. You can either use the SunOracle compiler or the Eclipse compiler. Calling the compiler API (both have documented APIs) will produce a .class file in a temporary location. You can then make a jar.

    For an example of this sort of thing, start with, for example, the Maven Compiler Plugin, which is a Java module which uses the compiler API. You'll have to find your way into the Plexus compiler module.

提交回复
热议问题