user1744056
user1744056

Reputation:

How to define a new Java class and create its instances at runtime?

I want to define a new Java class at runtime using some input information, for instance, from Files.readAllBytes(Paths.get(path)); and then map objects of this class to relational database via some ORM or persistence API (MyBatis, Hibernate). Is it even possible to do this and if yes how to achieve this (what libraries, tools etc.)? My own idea is to use Jython metaclasses, but I think there are simpler solutions.

Upvotes: 1

Views: 404

Answers (1)

IAdapter
IAdapter

Reputation: 64747

You can do it using The Compiler API

here is an example - http://www.accordess.com/wpblog/an-overview-of-java-compilation-api-jsr-199/

Upvotes: 2

Related Questions