tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason D. Burkert" <jason.burk...@craytek.com>
Subject Re: Set up postgresql on tomcat7
Date Wed, 17 Aug 2016 15:57:34 GMT
On 2016-08-17 5:32 AM, Andrew Davis wrote:
> Thanks.
>
> I can now deploy my servlets and they work ok, but..
>
> I had hoped to just deploy one copy of the postgres jar to my server and
> then be able to consume it inside multiple applications, instead of having
> multiple copies of the jar in multiple apps.

Try placing the postgres JDBC driver in Tomcat's lib directory.
For example: C:\apache-tomcat-7.0.69\lib

Then include your <Resource> defining the JDBC data source in Tomcat's 
context.xml
For example: C:\apache-tomcat-7.0.69\conf\context.xml

     <Resource
         name="jdbc/myPostgresConnection"
         auth="Container"
         type="javax.sql.DataSource"
         driverClassName="org.postgresql.Driver"
         url="jdbc:postgresql://localhost:5432/yourDatabaseName"
         username="postgres"
         password="postgres"
         validationQuery="select 1" />

Attribute driverClassName should reference a JDBC driver class inside 
the postgres jar.
Attribute name is very important and must match the value of 
res-ref-name inside your webapp's web.xml.

For example: C:\apache-tomcat-7.0.69\webapps\yourWebapp\WEB-INF\web.xml

     <resource-ref>
         <description>Requires named JNDI data source defined in 
Tomcat's context.xml</description>
<res-ref-name>jdbc/myPostgresConnection</res-ref-name>
         <res-type>javax.sql.DataSource</res-type>
         <res-auth>Container</res-auth>
     </resource-ref>

This will allow you to have one copy of the postgres jar deployed in 
Tomcat's lib directory,
and each of your webapps can reference the named connection (i.e. 
jdbc/myPostgresConnection )
within their own web.xml

-Jason


> I've been through the JNDI portion of the docs on Tomcat and found it still
> somewhat confusing.
>
> Andy...
>
> On Aug 17, 2016 4:06 AM, "André Warnier (tomcat)" <aw@ice-sa.com> wrote:
>
>> Andrew,
>> this list strips most kinds of attachments, so nobody saw your screenshots
>> or whatever was in them.
>> You need to copy/paste that text right into your message to the list (amd
>> make sure that you send your message as "plain text", not HTML, otherwise
>> it will be unreadable.
>>
>> On 17.08.2016 02:10, Andrew Davis wrote:
>>
>>> Well,
>>> This has not turned out how I wanted it to .
>>>
>>> I have 'a solution' but it isnt what I wanted to do.  I went back and re
>>> added the .jar file to the 'WEB-INF' folder and then deployed a new WAR
>>> file.
>>>
>>> Now things work just 'fine' BUT I suspect that this is not what a real
>>> coder would do and suspect I am still in the realms of hackery..
>>>
>>> [image: Inline image 1]
>>>
>>> Andy.
>>>
>>>
>>>
>>> On Tue, Aug 16, 2016 at 6:53 PM, Andrew Davis <drsockmonkee@gmail.com>
>>> wrote:
>>>
>>> I found the following in my logs..
>>>> from command line in Putty...
>>>>
>>>> cd /var/lib/tomcat7
>>>> tail -f logs/catalina.out
>>>>
>>>> [image: Inline image 1]
>>>>
>>>> I do have the jar file located in the following location on the machine..
>>>>
>>>> /usr/share/tomcat7/lib
>>>>
>>>> https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howt
>>>> o.html#JDBC_Data_Sources  is confusing to me.  It shouldnt but it is.. at
>>>> this point..
>>>>
>>>> Andy..
>>>>
>>>>
>>>>
>>>> On Tue, Aug 16, 2016 at 3:01 PM, George Sexton <georges@mhsoftware.com>
>>>> wrote:
>>>>
>>>> The best place to start would be to look at tomcat's logs for exceptions
>>>>> or errors.
>>>>>
>>>>>
>>>>>
>>>>> On 8/16/2016 12:44 PM, Andrew Davis wrote:
>>>>>
>>>>> Hello,
>>>>>> Im working on getting java servlets to run on my instance of Ububtu
>>>>>> with
>>>>>> tomcat7.
>>>>>>
>>>>>> I write my applications in Eclipse.. when i run my apps localhost
i see
>>>>>> everything just fine.
>>>>>>
>>>>>> When i export my WAR files i check the includ source files.
>>>>>>
>>>>>> I deploy the WAR file through tomcat manager.
>>>>>>
>>>>>> I can see the java classes which i use to insert records into my
>>>>>> postgresql
>>>>>> database. However,  there is nothing happening.  When i attempt 
to run
>>>>>> them, no joy.
>>>>>>
>>>>>> I have the postgresql .jar file installed on my headless ubuntu server
>>>>>> ,
>>>>>> but no luck.
>>>>>>
>>>>>> Aside from the .jar file is there anything else i need to configure?
>>>>>>
>>>>>> Any advice is welcome
>>>>>>
>>>>>> Andy
>>>>>>
>>>>>>
>>>>>> --
>>>>> George Sexton
>>>>> *MH Software, Inc.*
>>>>> Voice: 303 438 9585
>>>>> http://www.connectdaily.com
>>>>>
>>>>>
>>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>



Mime
View raw message