Note that there are some explanatory texts on larger screens.

plurals
  1. POTomcat not recognizing context in web service
    text
    copied!<p>I have a webservice running on tomcat (and working). I would like to extract the endpoint URL into a file outside the war, so that it can be changed without needing to redeploy the war. I am running locally with Tomcat 6 standalone on Windows XP.</p> <p>My thought was to have it in the Context, either as a context param or as an Environment variable. </p> <p>I wasn't sure which was better, and since I can't get the Context recognized, I have no idea which will work. So my first question, which of the entries below should I be using (if any)? </p> <pre><code>&lt;Context path="/myapp" docBase="myapp"&gt; &lt;Environment name="webserviceURI" type="java.lang.String" override="true" value="endpointURLredacted"/&gt; &lt;context-parameter&gt; &lt;name&gt;uri&lt;/name&gt; &lt;value&gt;endpointURLredacted&lt;/value&gt; &lt;/context-parameter&gt; &lt;/Context&gt; </code></pre> <p>Assuming the Environment line is correct, my code to retrieve is: </p> <pre><code>InitialContext ic = new InitialContext(); endpoint = (String)ic.lookup("webserviceURI"); </code></pre> <p>However....</p> <p>I have tried adding this in a context.xml file to the META-INF folder, and I was under the impression that when I deploy the war, to quote an answer from another question on here, "When you deploy the WAR, the context fragment (META-INF/context.xml) is copied to conf/Catalina/[host] directory." Well, that doesn't happen. I don't really want to do it that way, since I want the context to exist completely separately from the war, but it was a test to see if I could even get that far. Fail. </p> <p>So I tried adding the context xml (renamed to myapp.xml) to that folder (had to create it first) manually, but I still don't think the file is getting read. </p> <p>When I run the app I get an error like "javax.naming.NameNotFoundException: Name webserviceURI is not bound in this Context". </p> <p>I have tried printing out the initial context's environment:</p> <pre><code>Context: {java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory,java.naming.factory.url.pkgs=org.apache.naming} </code></pre> <p>So I don't think the context file is getting read, no matter where I put it. </p> <p>This isn't a servlet (which maybe it should be?) if that matters. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload