tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Wall <>
Subject Adding transactional classloader for dynamic code in webapp?
Date Mon, 07 Apr 2008 03:52:13 GMT
I'd like to allow a web app to define custom code, such as for custom 
data validators or data formatters to be added by a user through 
configuration in my web app. 

That is, I'd like to have a user of my web app specify some Java code 
snippets (either a few lines of code, or perhaps a complete method) that 
my base code would call back to do customized data validations if they 
have been configured in my web app.  An example would be a form that 
needs to validate a phone number, but some want a strict NPA-NXX-9999 
style format, others allow phone extensions, others may allow an 
optional country code prefix, etc.  So I'd like my based code to be able 
to do something like call a method the user has defined that follows a 
naming convention, such as

boolean validatePhone(String phone)

and it would then do the code check set by the user who perhaps only 
filled in the code snippet into a textarea in my JSP and I've saved to 
the database.

My guess is I'd need to develop some sort of transactional class loader, 
one that would be created after dynamically generating the Java code, or 
compiling the Java code entered and storing the resulting .class file, 
etc.  But since they could change the code through my web app, I would 
need to be able to auto-recompile (sort like a JSP does in Tomcat) and 
by recreating a new classloader on the fly, it would obsolete the old 
code during garbage collection and would use the new code going forward.

Is there any place that I can read about some proven approaches to this 
sort of dynamic Java class creation, compilation, class loader?  Tips? 


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message