简体   繁体   中英

Creating a Java Class using source code in a string

I have a String which contains the source code of an entire java class. My intention is to create a new class in another project folder using the code in this String. All this is to be done by code, not manually.

Is this possible in Java?

Since you are using String , I'm assuming you are talking about a class in Java source code form. If you are targeting JRE 1.6 or higher, you can use the JavaCompiler interface for turning this source code into a compiled Java class.

See Java API documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM