I'm making connection pools with JDBC using 'context.xml' on eclipse. It continues saying - Element type "Resource" must be declared. - Element type "Context" must be declared. - Element type "WatchedResource" must be declared.
The same code worked perfectly yesterday though. I just imported the project on the PC in my school. All the other files not using connection pools still runs correctly. I use Tomcat version 9.0
I copied the code that I typed yesterday, saved it as a text file. I deleted the 'context.xml' file then re-created. It still doesn't work. I searched on google and stack Over Flow to find out if anyone had the same problems, unfortunately I couldn't find any answer.
Is there anyone who could help me out please?
Here is the xml code that I typed.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE context>
<Context path="/" docBase="Webprj" reloadable="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource
name="jdbc/Oracle"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:xe"
username="sijeune" password="oracle"
maxActive="20" maxIdle="10" maxWait="-1"/>
</Context>
The root of my xml file is 'C:\Users\1027\Java\GroupStudy\Webprj\WebContent\META-INF\context.xml'
Thanks in advance!
I don't know why you are creating context.xml
separately in the project.
There is already a context.xml
file in the Tomcat conf
directory. Just add the datasource in the context.xml
From Tomcat 9 JNDI-Datasource Documentation :
Just add your datasource in it.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<Resource name="jdbc/myoracle" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
username="sijeune" password="oracle" maxTotal="20" maxIdle="10"
maxWaitMillis="-1"/>
</Context>
In the web.xml
:
Just add this :
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>