Accessing Resources defined in context.xml - Tomcat

Answered

Hello,

I have resources defined in the context.xml file that I have associated with my Web facet via "Tomcat Context Descriptor"

<Resource name="myPool" auth="Container" systemName="ABC" userName="USR" password="PWD" socketKeepAlive="true" maxPoolRecoveries="1" />

Tomcat starts without any issues.  However, when I call a servlet that looks to load from the InitalContext, it cannot find the resource as expected...

Context ec = (Context) new InitialContext().lookup("java:comp/env");
MyPool mp = (MyPool) ec.lookup("myPool");
# mp is null....

I've cast around here and SO and have not found anything useful yet.  Am I missing something?

I have verified that context.xml is being deployed to 

~\.IntelliJIdea2017.2\system\tomcat\...\conf\Catalina\localhost\myapp.xml





Thank you, John

0
5 comments

Does it work correctly if your app is deployed as a war outside of IntelliJ IDEA to the Tomcat server that you start manually?

0
Avatar
Permanently deleted user

Have you checked that your context.xml is not excluded from the build explicitly? In many cases you don't want context.xml in a packaged war file but during development. So if you are using maven you likely have something like the following in you pom.xml:

<build>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>META-INF/context.xml</packagingExcludes>
</configuration>
</plugin>
</build>

This way the context.xml file will be detected properly by IntelliJ, but will not be copied as it is lacking from the packaged war. You can either remove those lines (in most cases not an option) or place the context.xml in "Tomcat\conf\Catalina\localhost\NAMEOFYOURWAR.xml".

0
Avatar
Permanently deleted user

Same problem started with me today. Yesterday Intellij was correctly using the configured context file, today it auto generates an empty one. Didn't change any configuration.

0

Please check that:

1) context xml file name corresponds to the web app context path, if you need the context path to be 'my_app', you should specify '/my_app' as the value of the 'Application context' field on the Deployment tab of the run configuration.

2) if you need for the context xml file to have custom content, make sure that the 'Tomcat context descriptor' is specified in Web facet settings.

 

If problem remains, please clarify on:

>it auto generates an empty one.

where do you see this? Did you see different result before? And what has changed since it has worked list time?

Please also attach screenshots of all tabs of Run/Debug Configuration you are using for deployment, and screenshot of WEB facet settings for the module. 

0
Avatar
Permanently deleted user

I temporarily fixed the problem by renaming .IntelliJIdea2018.1 in the home directory to something else. Then at startup I told Intellij to import the 2017.3 settings.

In the Run settings I had to configure again where Tomcat 9 was located. Then it worked.

The location for the context file is here:

$HOME/.IntelliJIdea2018.1/system/tomcat/Unnamed_my_app_2/conf/Catalina/localhost/my_app.xml

0

Please sign in to leave a comment.