Hmm. I'm using an extension of the VelocityLayoutServlet, so what I was calling the context was actually a java class I configured in as a tool, via toolbox.xml. This class does not actually implement the Context (or any other) interface, although I could certainly do that if needed.
Here's the toolbox.xml: <?xml version="1.0"?> <toolbox> <tool> <key>setup</key> <class>com.myrio.qa.qas.SetupUI</class> </tool> <tool> <key>params</key> <scope>request</scope> <class>org.apache.velocity.tools.view.tools.ParameterParser</class> </tool> </toolbox> Here's the Velocity template code that invokes the runSetup() method: #if ($request.method=="POST") $setup.runSetup() #end Thanks, -Travis On Tue, 2005-02-01 at 11:37 -0800, Will Glass-Husain wrote: > Travis, > > When you say "context" do you mean an object that defines the Context > interface, or do you mean a web application? > > WILL > > ----- Original Message ----- > From: "Travis Bear" <[EMAIL PROTECTED]> > To: "Velocity Users List" <velocity-user@jakarta.apache.org> > Sent: Tuesday, February 01, 2005 11:23 AM > Subject: Classpath/Classloader issue with java program invoked via > Velocitycontext int Tomcat > > > > I'm really puzzled by an issue I'm seeing when I invoke an external > > object's main method from inside the Velocity context. All my code is > > running as a webapp inside Tomcat. The external object is a Jython > > script compiled into a java class via jythonc. This class is put into a > > jar file and placed in $CATALINA_HOME/webapps/$WEBAPP_NAME/WEB-INF/lib. > > > > When I invoke the Jython script from inside Tomcat, it breaks because it > > can't locate any of the packages I try to import from. The puzzling > > part is that the context itself is able to import from the same package > > that breaks the jython script, and it's running in the same VM. > > > > Here is the Jython script Setup.py: > > > > > > > > print "Entering Setup" > > from org.jtmb.sql import DataEngine > > from java.io import File > > propsFile = File("conf/DataEngine.properties") > > de = DataEngine.getStaticInstance(propsFile) > > print de.getString("select version as name from branch") > > > > > > > > Here is the code from the Velocity context where I statically invoke the > > jython script: > > > > com.myrio.setup.Setup.main(new String[]{}); > > > > Going on the theory that the context must have had a good classloader > > because it was able to instantiate the DataEngine, I attempted to load > > my class by explicitly using the same classloader: > > > > ClassLoader loader = this.getClass().getClassLoader(); > > Object setup = Class.forName("com.myrio.setup.Setup", true, > > loader).newInstance(); > > logger.fatal ("Attempting to load setup with custom classloader"); > > ((com.myrio.setup.Setup) setup).main(new String[]{}); > > > > > > In both cases, I get the same result. Here's the output in > > catalina.out. > > > > Entering Setup > > Traceback (innermost last): > > File "/home/travis/p4/3.5/qa/qas/code/jython/Setup.py", line 0, in > > main > > ImportError: No module named jtmb > > > > > > > > Thanks in advance -- this is my first effort at using classloaders, so I > > could easily be missing something. I'm pretty sure I could get it to > > work by manually setting the system classpath via system properties. > > But that seems like a pretty broken approach. Any help is appreciated! > > > > > > -Travis > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > _________________________________________________ > Scanned on 01 Feb 2005 20:24:56 > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]