Modularity

P

Paul Selibas

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.

Paul Selibas
 
N

NullBock

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
into.

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
JavaScript engine called Rhino (very stable, been around along
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

Walter Gildersleeve
Freiburg, Germany

___________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green
 
P

pkriens

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.

Kind regards,

Peter Kriens
 
E

ericaro

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top