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?

Answers


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.


  1. All methods must be part of a class.
  2. 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.

http://www.beanshell.org/

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.

If the method doesn't have to be coded in Java, then you can use the scripting API pretty much out-of-the-box, along with one of the standard scripting engines. (The JavaScript engine is very well tested, for example).


Need Your Help

Incrementing PK column from specific number(PostgreSQL)

sql postgresql auto-increment

In my PostgreSQL database I have table users which has two columns, PK named uid(serial) and user_type(integer). Is it possible that for regular users (of user_type 1) uid starts from 0 (and increm...

jQuery change background color on click

jquery html css animation flexslider

I try to make animated background color on active slide using flexslider, but i don't find any idea how to do it... so i tryed to make something simple but not working good.