2

I'm looking for a possibility to load the Java code dynamically into a class at the run time. The Java Code should be readed from an XML-file. There are just some "If-Then" expressions and should be added into one class and use it like any other class in my project.

Actually my file contains some rule codes which i want to load like cache and use this class further

Does someone know if it is possible in java?

best regards
Abhij

3
  • May I ask why the code is in XML? Commented May 11, 2012 at 13:03
  • 1
    Good god(s) consider using a Groovy, JRuby, etc DSL instead: way less work, and much easier to deal with. Commented May 11, 2012 at 13:06
  • Actually it contain some ruleCode of organization like C01|((customer=registered) and (sales>70000)) then it is of type C01 Commented May 11, 2012 at 13:26

1 Answer 1

2

I believe you can do this with CGLib, but I haven't done more than use it to mock classes at runtime. If dynamic code is a major aspect of your application you should consider using a language like Ruby which has much better support for running code read in at runtime.

Sign up to request clarification or add additional context in comments.

2 Comments

As a script language you can use beanshell.org - it's syntax is very Java-like
You could also use javassist, or just leverage the existing java compilation api... But I agree using a dynamic language is a better solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.