Trouble with Dynamic Compilation in Tomcat

I have some code that is dynamically generating Java classes and compiling them based on reflection against existing, but arbitrary, classes.

My code is:

com.sun.tools.javac.Main.compile(new String[] { "-d", classDirectory, src.getAbsolutePath() });

And it works just fine under Orion.

Under Tomcat, however, it fails to find any of the classes in the web application's classpath.

While I know I can pass in the -classpath argument, I have no way in this library of knowing what the classpath should be since the classes I am operating on are arbitrary.

Any thoughts on how I get one of the following to happen:

a) the compiler leverage the classpath available to the web application

OR

b) identify what the current classpath is so I can pass it to the compiler

Solutions that rely on tomcat-specific calls won't work as the solution needs to be cross app server/

Thanks

[945 byte] By [NSPollutiona] at [2007-10-3 11:49:46]
# 1

If you can get the current class loader and it is an instance of java.net.URLClassLoader,

then you can get the class path with URLClassLoader.getURLs(). That is solution b).

For solution a), javac needs to be able to compile against a class loader. We have an RFE

for that, but it is currently not possible:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6297388

PeterAhea at 2007-7-15 14:23:21 > top of Java-index,Developer Tools,Java Compiler...
# 2
Thanks.I actually ended up using a bit of an odd third option that does not really solve the underlying problem.Specifically, I rewrote the API to have protected methods that accept strings instead of class objects. It's not typesafe, not ideal, but it functions.
NSPollutiona at 2007-7-15 14:23:21 > top of Java-index,Developer Tools,Java Compiler...