I am using Tomcat 8.5.6 inside Eclipse 4.6.1. I have a foo web application project / context that has a JAX-RS endpoint (using RESTEasy 3.1.0.CR3) bar , so I can run Tomcat inside Eclipse and access:
http:
I have a variable called foobar that I want to get in my JAX-RS implementation using JNDI:
final String foobar = (String) new InitialContext().lookup("java:comp/env/foobar");
I plan to deploy the WAR produced in production using Tomcat autodeploy. I want to configure foobar variable for Tomcat externally in WAR. How can I do this to test it in Eclipse?
After a lot of reading, I found what I considered $CATALINA_HOME Eclipse: …\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\ . So I created a context file for foo in …\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\foo.xml to fit my project / context and put the following inside it:
<?xml version="1.0" encoding="UTF-8"?> <Context> <Environment name="foobar" type="java.lang.String" value="123"/> </Context>
Yes, I know that Eclipse erases this directory whenever I rebuild. But after construction, I saved the file, at least I want to see if it works. This is not true. I get an error message:
javax.naming.NameNotFoundException: Name [foobar] is not bound in this Context. Unable to find [foobar].
I want to at least get it working so that I can know how to do this during production and worry a bit about the problem of deleting the context file in Eclipse. So what have I done wrong? Why can't Tomcat in Eclipse find this JNDI variable?
Note. I do not use the web.xml and do not want to do this; in addition, this variable must be defined outside the WAR in the production deployment.
Update. The good news is that (on Windows 10 Professional Anniversary Edition 64-bit), using the same Tomcat, but offline, I put the same foobar.xml file in the offline Tomcat conf\Catalina\localhost\foo.xml , and my JAX- RS application is great. So, how can I define a JNDI variable in Tomcat inside Eclipse for testing?