
Originally Posted by
kate.sherwood@tasktop.com
Hi, Paul.
This is "as designed" functionality, but there have been enough people bitten by this that we will have to rethink our design. I can't get to it today, and am (probably) going on vacation tomorrow for a few days, but I will take a look at it on Monday at the latest.
Hi Kate,
Thanks for the reply. I have finally worked this out (although probably not the most ideal way to do it I'm sure). I think this could be a pitfall for developers who are used to working with say netbeans (like me) and using a stand alone tomcat installation with the freedom to edit the configuration in any way you like.
Anyway just in case some one in the future does need to do this, and it may be blatantly obvious to people if you use eclipse or STS all the time (please forgive my ignorance) here is how I did it.
1) In STS, in the servers tab double click your tomcat or VmFabric server. Check the box in the server options area titled "Publish module contexts to separate XML files". This may be unnecessary but I never add my contexts to the server.xml (this may be fine in development though I dont know) and prefer to have a separate xml file for this. Anyway this will give you the /Catalina/localhost/myapp.xml context file.
2) Navigate to your workspace for the project you need jndi in. Now browse to the following directory (adjust to your needs) C:\EclipseWorkingFolder\.metadata\.plugins\org.ecl ipse.wst.server.core\tmp1\wtpwebapps\myapp\META-INF
3) Place a file called context.xml into this directory, again this might not be the best way to do this but it works for me and if there is a better way I would really like to know. The content of this file can contain whatever you would like to embed within your context tags in your tomcat application context: EG
Code:
<Context>
<Resource name="jdbc/bspDb" auth="Container" type="javax.sql.DataSource" username="user" password="password" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@DEVDB1:1521:DEV1" maxActive="8" maxIdle="4"/>
</Context>
4) Redeploy your application to the server and now browse to C:\EclipseWorkingFolder\.metadata\.plugins\org.ecl ipse.wst.server.core\tmp1\conf (tmp1 is where my application is deployed but dependent on how many servers you have deployed you could have more or less directories so it might not be tmp1)
In the conf directory you should now see your Catalina\localhost directories like in a standard tomcat install which is where you would place your context files
5) Further drill down into C:\EclipseWorkingFolder\.metadata\.plugins\org.ecl ipse.wst.server.core\tmp1\conf\Catalina\localhost
You should now see a context xml file there: myapp.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="C:\EclipseWorkingFolder\.metadata\.plugin s\org.eclipse.wst.server.core\tmp1\wtpwebapps\myap p" reloadable="true" source="org.eclipse.jst.j2ee.server:myapp">
<Resource auth="Container" driverClassName="oracle.jdbc.OracleDriver" maxActive="8" maxIdle="4" name="jdbc/bspDb" password="password" type="javax.sql.DataSource" url="jdbc:oracle:thin:@DEVDB1:1521
EV1" username="USER"/>
</Context>
Anyway this seems to work for me and gives me the desired results. I know to most its probably quite obvious but to people new to eclipse, STS or to using embedded servers then it might not be so obvious so hopefully this could be of some help to those people.
Thanks,
Paul