7

I have a Tomcat 7 Server in Eclipse with two webapps a and b and need to find out how to have application specific configuration files for tomcat that works with Eclipse.

Now I want for each webapp a custom config file, like described here: Apache Tomcat: multiple webapps. So I created a <TomcatDirectory>/conf/Catalina/localhost folder and put the a.xml and b.xml there. This works fine when I run Tomcat from command line.

But where have I to put the application specific configuration files a.xml and b.xml when I run Tomcat from within eclipse?

I already tried to put the files in Eclipse in <EclipseWorkspace>\Servers\<ServerName>\conf\Catalina\localhost\ but WTP does not copy this files to <EclipseWorkspace>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost

Community
  • 1
  • 1
David
  • 208
  • 2
  • 5
  • 1
    Why not to put this file into the appropriate webapp project? – Aleksandr M Oct 06 '14 at 10:12
  • 1
    The files are located in the server, because they contain server specific configurations like database connection and passwords. (Because this configurations differ from server to server, one can not put them in the application) – Ralph Oct 06 '14 at 10:31

3 Answers3

3

Leave them in <TomcatDirectory>/conf/Catalina/localhost

Server > Open > Server Locations

Change from: Use workspace metadata To: Use Tomcat instalation

Now a.xml and b.xml from <TomcatDirectory>/conf/Catalina/localhost will be used.

bigGuy
  • 1,732
  • 1
  • 22
  • 37
  • Thanks for your answer! It works quite good, but i have the problem that on redeploy it resets my config files to the default ones. – David Oct 15 '14 at 15:05
  • My guess is, on redeploy it takes files(context.xml etc.) from \Servers\. Update them. – bigGuy Oct 16 '14 at 08:15
  • 1
    The context.xml only contains `WEB-INF/web.xml`. But it replaces my two config files for example with ``, so the contexts for the single webapps. If i don't add the webapps in eclipse, it just deletes my configs on publish. – David Oct 17 '14 at 12:26
  • What context.xml you have in \Servers\? When you start server on eclipse, it will take config files \Servers\ and will write them on /conf – bigGuy Oct 17 '14 at 12:31
1

If it's for development's purpose, you can specify a folder into the "docBase" attribute of context file like this :

<?xml version="1.0" encoding="UTF-8"?>
<Context crossContext="true" docBase="C:/devel/MyApp/web/target/MyApp-web" path="/MyApp" reloadable="true">
    <Resource
        ... />
</Context>

By adding these context files directly into /conf/Catalina/localhost, everything is configured and should work like you want but you'll have to stop the tomcat server every time you'll want to clean and build your project.

Fabien Thouraud
  • 909
  • 1
  • 11
  • 21
0

What you are looking for is to have context.xml files for two different applications.create context.xml file under web application's (a and b) META-INF folder and you should be able to run both the application with their own context.xml file. In eclipse you should be able to create META-INF folder for your respective web applications in parallel to WEB-INF directory

  • The context files can't be put in the application, because they are not the same for all servers -- that is why they are located in the server. – Ralph Oct 06 '14 at 10:33
  • I think David has mentioned specific server,Tomcat, and context.xml works fine in Tomcat. –  Oct 06 '14 at 11:16
  • application specific config files located in /conf/Catalina/localhost (with an link to an question/answer that describe this technique) -- I do not know how to express it better - do you have an idea? - btw. David is my college and I recommended him to post his question at stack overflow – Ralph Oct 06 '14 at 11:18