This might be far fetched, but i really need to know if its possible to read a java expression from a text file and execute it. Example : width = imgwidth - 100; Where the variables r defined and known by the class that read this line.
Thanks in advance!
Joined: Jul 17, 2004
that is possible. In the general case it is quite hard. For a simple construct like your example there is an easy way, however:
There are a number of libraries that allow you to do that. Google for JEP or JEL. JEP builds an expression tree and interprets it using values, which makes it a bit slow. JEL compiles the expression, which is much faster, but can be tricky to handle to situations where you have multiple classloaders. For the ultimate Java integration, look for Javassist, which lets you build your own Java classes from Strings of code - very cool.