Can java import text methods
To make my question abit more specific I'm wondering if a compiled java program can import methods from a simple "text.txt" file, basiclly from text characters?? Is this possible? If so how?
Yes it is possible, here is an example of how to do it: example. On that page a string is compiled but it is the same basic principle. If you read the stuff in your text file into a string you can do the same thing.
- All methods must be part of a class.
- You can only use methods in bytecode.
IFF your text file defines an unique class, you can use the Java Compiler API and reflection to use such a method.
This can be done easily using BeanShell.
Been around for years, rock solid, works.
It can, but if you want those methods to be written in standard Java then it will require a bit of technical creativity.
Essentially, you can use the "Scripting API" ( http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html ). This API allows you to execute "scripts" in any language as part of your greater Java application. To get it to run Java, you'd need to create a ScriptEngine implementation which could take the source, run it through the compiler API ( http://docs.oracle.com/javase/6/docs/api/javax/tools/JavaCompiler.html ), and execute it.