Tomcat Server fails to start - java

Problem:
When I try to add following code to context.xml of Tomcat 7 It gives this error.
(NOTE: I'm adding this code from inside the Eclipse)
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource
name="jdbc/UsersDB"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/usersDB"
username="root"
password="secret"
/>
</Context>
Error:
Could not load the Tomcat server configuration at \Servers\Tomcat v7.0 Server at localhost-config. The configuration may be corrupt or incomplete.
Element type "Resource" must be followed by either attribute specifications, ">" or "/>".
And when I remove this code and save context.xml , Server starts successfully without doing anything (Refreshing and all).
What I have tried:
Referred This question:
publishing failed with multiple errors eclipse
Tried closing Eclipse and opening again.
Tried closing and opening peoject again.
Nothing is working.
What should I try Now?
UPDATE:
Tomcat server started successfully. I just typed everything in context.xml rather than copy paste the code. It could be some encoding problem I guess in copy pasting the code directly into eclipse file.

This is how it should look . Resource should be properly enclosed within the Context. Like:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/webAppName">
<Resource
name="jdbc/UsersDB"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/usersDB"
username="root"
password="secret" />
</Context>

I have similar thing working. All the difference - I have one single row, not multiple lines like you have. Try it in a single row. Plus before you copy it to eclipse, try copy it to notepad, or another simple editor to remove invalid chars.

Related

Tomcat not executing the correct realm

I am working on a tomcat 7 webapp that I recently inherited. We are working on migrating from Tomcat 5.5.
The webapp uses a tomcat realm to handle a combination of ldap/sql authentication.
When I define my context.xml as follows
<Context docBase="*******" reloadable="false">
<Realm className="com.******.tomcat.auth.LdapSqlRealm"
****
/>
<Resource name="jdbc/*****"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
validationQuery="SELECT 1"
validationInterval="30000"
timeBetweenEvictionRunsMillis="60000"
maxActive="15"
maxIdle="15"
maxWait="30000"
initialSize="10"
removeAbandonedTimeout="60"
removeAbandoned="true"
logAbandoned="true"
minEvictableIdleTimeMillis="60000"
numTestsPerEvictionRun="2"
jmxEnabled="true"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
username="*****"
password="*****"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="*****"
/></Context>
I can see my realm initializing in the logs, but when I go to authenticate (using basic) it doesn't use my realm.
If I define the realm in the server.xml file it works just fine.
Any thoughts on why I can't define it in the context.xml.
Our context.xml file is actually located in cont/Catalina/localhost/*****.xml
I have tried starting from scratch with simple realms, or extensions of RealmBase and they all do the same thing.
Thanks,
Travis
Turns out that I had an extra <Context /> tag in my <Host /> tag in my server.xml which was messing up my context.xml file.
Little Santi tipped me off by suggesting a vanilla build of tomcat, which I didn't end up doing, but I did a compare of server.xml from the two and spotted the issue right away. Wish I had thought of it sooner.

tomcat embedded jndi data source maven

I add to pom.xml tomcat embedded and his created in the target folder. I don't know how to configure jndi in tomcat, in target/tomcat/conf i don't have contex.xml when i manually created it and add
<Resource name="jdbc/MyDB"
global="jdbc/MyDB"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#localhost:1521:orcl"
username="hr"
password="oracle"
maxActive="100"
maxIdle="20"
minIdle="5"
maxWait="10000"/>
and clean maven project everything disappear. Where to put configuration file in maven project and how to properly configure it.

Tomcat SQL doesn't refresh

I have a Java RESTful Webservice running on Tomcat7 in Ubuntu.
When I change fields in the Database the Webservice returns the old values.
When i restart the service, it returns the new values.
this is my Context.xml:
<Context>
<Resource name="jdbc/schischule"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://IP:3306/Skischul_DB"
username="admin"
password="pwd"
maxActive="20"
maxIdle="30"
maxWait="-1"
/>
</Context>
Has anyone an idea why Tomcat doesn't refresh the data?
THX

Tomcat JNDI resource name aliases

Is it possible to create a JNDI tomcat resource with multiple names (synonyms, aliases)?
Something like
<Resource
name="jdbc/product-ds"
alias="jdbc/product-cfg-ds"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
...
/>
I need this, because there are two modules which use the same DataSource, but with different JNDI name. The simplest solution will be to sync those names, but unfortunately it's not possible at the moment.
You can do this. It took me a while to work out the correct sequence. What you need to do is define the jdbc/product-ds in your server.xml (tomcat/conf/server.xml) in the GlobalNamingResources section kind of like this:
<GlobalNamingResources>
<Resource name="jdbc/product-ds " auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#127.0.0.1:1521:mysid"
username="scott" password="tiger" maxActive="20" maxIdle="10"
maxWait="-1"/>
</GlobalNamingResources>
Then you can rename this in your server context.xml (tomcat/conf/context.xml)
Like this:
<ResourceLink
name="jdbc/product-cfg-ds"
global="jdbc/product-ds"
type="javax.sql.DataSource"/>
The global name is then renamed for all applications deployed on the the server. I don't think the global jdbc/product-ds will be available in any application, if you did want it you'd need to add:
<ResourceLink
name="jdbc/product-ds"
global="jdbc/product-ds"
type="javax.sql.DataSource"/>

Eclipse Tomcat creating 3 duplicate JNDI connection pools

On one developer workstation running Eclipse Helios SR2, Windows 7 and Tomcat 6.0.32 we have a very strange case of duplicate JNDI connection pools
Running tomcat from Eclipse
server.xml
>
<Context docBase="path to web app" path="/ds-web" reloadable="true">
<Resource
name="jdbc/ds"
username="ds"
password="pass"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/ds"
auth="Container"
driverClassName="org.postgresql.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
logAbandoned="true"
maxActive="30"
maxIdle="10"
maxWait="1000"
removeAbandoned="true"
removeAbandonedTimeout="60"
validationQuery="SELECT 1"
testOnBorrow="true"
testOnReturn="true"/>
</Context>
When start server, on the console we see the following 3 times in a row
AbandonedObjectPool is used
(org.apache.commons.dbcp.AbandonedObjectPool#11aa58b)
LogAbandoned: true
RemoveAbandoned: true
RemoveAbandonedTimeout: 60
Application then fails to find the JNDI resource
If we remove the <Resource> in server.xml, then the console shows no connection pool is created at all
On another developer machine with the same hardware and OS we do not have this problem
Any ideas?
Thanks
Marc
My suggestion, Copy the whole <Context> from server.xml and create a blank context.xml inside your web application META-INF folder and paste the <Context> copied from server.xml there.
Restart your application and see if this works.
We re-installed postgresql on the machine and the problem got solved somehow.
We're thinking something in the original postgresql config had been messed up and tomcat was failing to connect to the BD somehow. I guess tomcat was simply "trying 3 times", thus the triple output.
Another unsolved mystery...
move
<Resource
name="jdbc/ds"
username="ds"
password="pass"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/ds"
auth="Container"
driverClassName="org.postgresql.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
logAbandoned="true"
maxActive="30"
maxIdle="10"
maxWait="1000"
removeAbandoned="true"
removeAbandonedTimeout="60"
validationQuery="SELECT 1"
testOnBorrow="true"
testOnReturn="true"/>
to server.xml namely the
<GlobalNamingResources>
element
in your conf/context.xml file you would instead specify
<ContextLink name="jdbc/ds" global="jdbc/ds"/>
and this way, the three contexts will share the same pool.

Categories