Ño you can't. The point is that java needs to be compiled to byte code to be able to be executed. Why do you want this?
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
4
posted
0
Welcome to the Ranch
You could try writing the entire code of a class into a text file, giving it a .java extension, and using Runtime.exec() both to compile and execute that class.
But then, why on earth would you want to do that?
William Brogden
Author and all-around good cowpoke
Rancher
You could try writing the entire code of a class into a text file, giving it a .java extension, and using Runtime.exec() both to compile and execute that class.
But then, why on earth would you want to do that?
Thanks.
I will try this. This reason i want this is to emulate something like Server side js. I would have used it but the code base is using java 1.5. So required some thing like this
I think something like BeanShell or Groovy is as close as you'll get to what you're looking for.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
apurav chauhan
Greenhorn
Joined: Aug 07, 2010
Posts: 21
posted
0
As far as i know, scripting is supported in java 1.6. As i already quoted Campbell Ritchie, my java is 1.5. And i dont have the option to upgrade it to 1.6.
apurav chauhan
Greenhorn
Joined: Aug 07, 2010
Posts: 21
posted
0
Wouter Oet wrote:Assuming that js stands for JavaScript: you can run JavaScript directly on the JVM using the javax.scripting package. Look for example here
You are right Wouter. BSF is the right thing for me using java 1.5.
Thanks man.
Lester Burnham
Rancher
Joined: Oct 14, 2008
Posts: 1337
posted
0
BSF is cool (assuming that it's JavaScript). If it's Java, then the Javassisst library can turn it into an executable class (all in memory, no file access needed).