ArrayList<Employees> eList = //call from tomcat app that returns an Employee List or ArrayList
Is this possible? Thanks!
While it's possible to call into another application by a number of means (sockets, RMI, web services, ...), can you clarify why the method needs to run inside of the web app? Can't the relevant classes be part of the CLI application as well? Or do you need access to runtime objects of the web app?
Hi, I think what I need are runtime Connection object of the application. Right now, when I try to run the app I get this error.
E:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\zstats\WEB-INF\cl
Starting daily backup...
javax.naming.NoInitialContextException: Need to specify class name in environmen
t or system property, or as an applet parameter, or in an application resource f
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
Connection pooling works ok in my webapp but not in my standalone app. I didn't want to rewrite the database methods that I already created that's why I chose to put the standalone app inside the webapp itself. The standalone app will be called using a cron scheduler to make daily backups of the database.
1) You have a webapp in Tomcat, which are doing CRUD-stuff on a database.
2) You (want to) have an application doing other stuff on the database too.
In order to achieve 2), you want to reuse the stuff you did in 1) as much as possible. Sensible.
I didn't want to rewrite the database methods that I already created that's why I chose to put the standalone app inside the webapp itself.
Have you considered moving your database methods outside the webapp instead of moving your standalone app inside the webapp? Make a separate project and .jar-file which you call from either of your apps?
[ December 19, 2006: Message edited by: �dne Brunborg ]
Tomcat provides a naming service that you can access via JNDI from your web application. You probably declare the Tomcat connection pool in a Tomcat XML configuration file (server.xml). In your web application, you're looking up the database connection pool that Tomcat has put in the naming directory for you.
When you run a stand-alone application (outside of Tomcat), you don't have access to Tomcat's naming service directly. So when you try to lookup something via JNDI, it will not be found - JNDI isn't even configured (that's what the error message says).
Ofcourse you can access the database from a stand-alone application, but you can't use Tomcat's connection pool easily; you need to make sure that you connect to Tomcat's naming service to do this. It might be easier to just make a directy JDBC connection to the database from your stand-alone tool. The stand-alone tool is a tool to backup the database, isn't it? It doesn't really need to use a connection pool anyway. (One of the reasons to use a connection pool in a web app is to control the number of connections to the database, regardless of how many users are using the web app - your backup tool just needs 1 connection).
I believe there is a way to turn on remote JNDI service in Tomcat. Something with activating / running some kind of service in Tomcat, that will sit on a fix known port, and route requests to the internal JNDI service.
I thought that I saw examples of this, with either the Apache or JBoss documentations... not much help, but maybe this is a small start.