Good day everyone...
I have a question and any bit of advice would be appreciated.
What would be the easiest possible way to implement a scripting system
in a java program so that you can have a core + modules kind of system.
Or even perhaps compile Java code at runtime. Is this even possible?
What i want to do it make a core and other people can program modules
that will just fit in without changing the core program.
Many thanks to those who contribute.
You've lot's of different ways of implementing this. And you don't
have to require run-time compilation either, merely realease a public
API that the module creators can use. We do this fairly extensively
with our products, releasing a fairly large API that users can click
If you do want to go run-time, there are a few things you could
consider. For instance, the Mozilla orginazation has a great pure-Java
time)--go to http://mozilla.org/rhino. There are engines for almost
every language around, including Java. JavaWorld ran a comparison of
different engines a couple years back : http://linkfrog.net/daao
Free and easy, small and green
Take a look at Beanshell. It is a lightweight scripting language that
is very close to Java. This closeness makes it work very well with
standard Java objects.
If you want to build such an extendable model, it might also be worth
to take a look at the OSGi specifications. They form the foundation of
the Eclipse IDE. The OSGi specifies a small framework that manages the
modularity and lifecycle issues of a plugin based model.
you can also read at runtime a .properties file that contains a comma
separated list of fully qualified class
Instanciate using reflexion thoses classes (assuming they are in the
classpath), cast them as com.yourpackage.YourPluginInterface, and use
this list in your core program.
To get thoses classes in the classpath at runtime, set a directory for
"plugins", and instanciate an URLClassLoader, that "loads" all jars in.
Its very very basic and simple yet performant as far as your
application is not build upon thousands of different plugins type.
|All times are GMT. The time now is 08:51 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.