You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Aaron Hackney <aa...@aaronhackney.com> on 2005/06/01 02:49:57 UTC
Re: context battle?
Patrick, Thanks *SO MUCH* for the response. I tried your recomendation
using Tomcat 5.5 and it worked as you stated in your inline post.
I was pulling my hair out trying to replicate my success with JBuilder
2005.
I finally figured it out:
I followed your directions below with 1 exception. In JBuilder, the IDE
ignores the tomcat config, as near as I can tell, and generates it's own
server.xml file in the project directory called "server8080.xml".
Server8080.xml creates the context for the webapp. For whatever reason,
it ignores the META-INF/context.xml. So, by putting the <Resource> in
the server8080.xml and following the rest of the information in your
inline post, I *FINALLY* am able to use a datasource from my classes and
JSP's within JBuilder.
This has had me stumped for a few days......It feels good to solve the
problem.
I know this isn't the BEST solution, but I can continue to develop my
app.....
If someone has a better workaround for JBuilder, PLEASE SHARE!
Here's my file info. I hope it helps someone else out.
Thanks again!
-Aaron
*********************************************************************
** server8080.xml found in
..../jbprojects/myproject/Tomcat/conf/server8080.xml
** this is autogenerated by jbuilder. you can modify this so jbuilder
doesnt over write it
*********************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<Server debug="0" port="8081" shutdown="SHUTDOWN">
<Service name="Catalina">
<Connector acceptCount="10" connectionTimeout="60000"
debug="0" maxThreads="75" minSpareThreads="5" port="8080"/>
<Engine debug="0" defaultHost="localhost" name="Catalina">
<Host appBase="/Users/aaronhackney/jbproject/untitled5/Tomcat/webapps"
autoDeploy="false" debug="0" deployXML="false"
name="localhost" unpackWARs="false">
<Context debug="0"
docBase="/Users/aaronhackney/jbproject/untitled5/WebModule1"
path="/WebModule1" reloadable="true"
workDir="/Users/aaronhackney/jbproject/untitled5/Tomcat/work/WebModule1">
<Resource
name ="jdbc/helloworld"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1/mydatabase"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="user"
password="mypassword"
/>
</Context>
</Host>
</Engine>
</Service>
</Server>
*********************************************************************
** web.xml found in ..../jbproject/untitled5/WebModule1/WEB-INF/web.xml
*********************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLo
cation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>WebModule1</display-name>
<resource-ref>
<description>Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.</description>
<res-ref-name>jdbc/helloworld</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet>
<description>Added by JBuilder to compile JSPs with debug
info</description>
<servlet-name>debugjsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>classdebuginfo</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>debugjsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
</web-app>
Patrick Thomas wrote:
>Damn, he found it. We try to hide those HOW-TOs really well. ;)
>
>Aaron,
>
>Yeah, that's the right place to look; sorry I didn't include that in
>the first reply, but I didn't want to muddy the waters if that wasn't
>your real issue. I'm inlining an email that I sent to the list a few
>months ago. It's not on the exact same issue, but the example may help
>you get some clarity.
>
>Good Luck,
>Patrick
>
>
>---- Forwarded Message ----
>From: P T <ps...@gmail.com>
>Reply-To: P T <ps...@gmail.com>
>To: Tomcat Users List <to...@jakarta.apache.org>
>Date: Apr 8, 2005 1:31 PM
>Subject: Re: Add Context Path, Tomcat 5.5.7
>
>Scott,
>
>I feel your pain -- I just finished sorting out that whole thing
>myself. One thing I'd definitely recommend doing is installing the
>admin tool for tomcat 5 and using it to change something trivial in
>your server.xml file. When it gets done making the change it strips
>out all the comments as a side effect and makes the file *much*
>cleaner and, in my opinion, more readable. As for your question:
>if the resource is to be used for multiple applications, you could put
>it in the server.xml... if not (and I'm going to presume that's the
>case for you -- let me know if not) then you're much better off using
>your application-specific WEB-INF\web.xml and META-INF\context.xml
>files like so:
>
>
><your application docbase>\META-INF\context.xml would look something like:
><Context path="/Foo"
> docBase="C:/Foo"
> debug="1" reloadable="true">
> <Resource
> auth="Container"
> name="jdbc/aNameForYourDBresource"
> type="javax.sql.DataSource"
> password="Foo"
> driverClassName="oracle.jdbc.driver.OracleDriver"
> maxIdle="3"
> maxWait="5000"
> username="Foo"
> url="jdbc:oracle:thin:@Foo:1521:Foo"
> maxActive="15"/>
> <WatchedResource>WEB-INF/web.xml</WatchedResource>
> <WatchedResource>META-INF/context.xml</WatchedResource>
></Context>
>
>and your <your application docbase>WEB-INF\web.xml would then
>reference the resource defined in the context above (the res-ref-name
>should match the resource name)....
>
><?xml version="1.0" encoding="ISO-8859-1"?>
>
><!DOCTYPE web-app
> PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> "http://java.sun.com/dtd/web-app_2_3.dtd">
>
><web-app>
>
> <display-name>Your app's name</display-name>
> <description>
> Slices, dices and makes fresh canned spam!
> </description>
>
> <resource-ref>
> <description>Description of Datasource</description>
> <res-ref-name>jdbc/aNameForYourDBresource</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
></web-app>
>
>It's helpful to think of the individual application context.xml files
>being 'included' as <context> entries in the server.xml file (almost
>like an @include, except implicit).
>
>Hope that helps! Let me know if I can clarify anything.
>
>Cheers,
>Patrick Thomas
>
>(PS - remember to install the jakarta commons and pooling jars
>mentioned in the dbcp documentation.)
>
>
>On 5/31/05, Aaron Hackney <aa...@aaronhackney.com> wrote:
>
>
>>I think I may have actually found the answer to my own question....does
>>this look like the right path to go down?
>>
>>http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html
>>
>>?
>>
>>Thanks
>>-Aaron
>>
>>Aaron Hackney wrote:
>>
>>
>>
>>>Thanks for the response Patrick. I'm probably going about this all wrong.
>>>
>>>Simply put, I'm just trying to make a datasource available to my
>>>application. Sounds sinple enough. I have found a lot of conflicting
>>>information out there on the implementation.
>>>
>>>I develop with JBuilder (good, bad or indifferent!) But
>>>anyhow....where does one properly make a datasource for a tomcat
>>>application available? I'm using Tomcat 5.0 (I could use 5.5 if I had
>>>to).
>>>
>>>Thanks in advance. I'm a bit blind and stubling around here and really
>>>tried to research it on my own this weekend but to no avail.
>>>
>>>-Aaron
>>>
>>>Patrick Thomas wrote:
>>>
>>>
>>>
>>>>>and if a context with the same name is defined in a webapp WEB-INF/xml
>>>>>file which would "win" such a fight? I have a feeling my context
>>>>>defined
>>>>>in /localhost is being overwritten by the app. (I'm fighting with
>>>>>JBuilder 2005 trying to get some JNDI naming stuff to work for my
>>>>>datasources)
>>>>>
>>>>>Ideas? Or am I waaaaay off?
>>>>>
>>>>>
>>>>>
>>>>I'm gonna go with "possibly way off" because you shouldn't be putting
>>>>the context name into web.xml (context.xml is okay, though not
>>>>required, but web.xml no... in fact, I don't think it'll even
>>>>acknowledge it there). Did you mean to say "META-INF/context.xml"? If
>>>>so, then we've got a meatier discussion; let us know.
>>>>
>>>>Cheers,
>>>>Patrick
>>>>
>>>>On 5/31/05, Aaron Hackney <aa...@aaronhackney.com> wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>Hello. I'm hoping someone can help me with a context question.
>>>>>
>>>>>If I define a context in an xml file in
>>>>>/tomcathome/conf/catalina/localhost
>>>>>
>>>>>and if a context with the same name is defined in a webapp WEB-INF/xml
>>>>>file which would "win" such a fight? I have a feeling my context
>>>>>defined
>>>>>in /localhost is being overwritten by the app. (I'm fighting with
>>>>>JBuilder 2005 trying to get some JNDI naming stuff to work for my
>>>>>datasources)
>>>>>
>>>>>Ideas? Or am I waaaaay off?
>>>>>
>>>>>Thanks in advance.
>>>>>-Aaron
>>>>>
>>>>>--
>>>>>************************************************
>>>>>Aaron Hackney
>>>>>MCP, MCSA, MCSE 2003/NT4, MCT,
>>>>>Net+, A+, CCNA, CCDA, CCAI
>>>>>aaron@aaronhackney.com
>>>>>http://www.aaronhackney.com
>>>>>309-472-7033
>>>>>************************************************
>>>>>
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>>>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>
>>--
>>************************************************
>>Aaron Hackney
>>MCP, MCSA, MCSE 2003/NT4, MCT,
>>Net+, A+, CCNA, CCDA, CCAI
>>aaron@aaronhackney.com
>>http://www.aaronhackney.com
>>309-472-7033
>>************************************************
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
--
************************************************
Aaron Hackney
MCP, MCSA, MCSE 2003/NT4, MCT,
Net+, A+, CCNA, CCDA, CCAI
aaron@aaronhackney.com
http://www.aaronhackney.com
309-472-7033
************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org