Configure the project in eclipse so that it falls into the "normal" tomcat class loader

I have two tomcat web applications that need to exchange information using a singleton. I already did this by putting the jared classes in the tomcat shared directory. Then each webapp receives the same copy of singleton. What I would like to do is integrate this behavior into eclipse. I would like the generic classes to be one project that is included in the tomcat generic classloader every time I start the tomcat server in eclipse. Does anyone know how to configure eclipse for this?

+4
source share
2 answers

I managed to get it to work. Here is what I did:

  • Created a common project in the eclipse workspace.
  • Created two web applications called first and second , which should share a common project.

When creating web applications, the Servers project is created with the tomcat configuration.

  • Modify catalina.properties inside the Servers project and add the line shared.loader=/path-to-workspace/common/bin .

This works great for development. Every time a new assembly is created, everything is synchronized. To deploy, you need to convert the common project to common.jar and put it in ${catalina.home}/lib .

+1
source

Perhaps one of the possibilities could be to expand the tomcat classloader so that this classloader searches in other directories than WEB-INF/lib , as follows:

  • Extension org.apache.catalina.loader.WebappClassLoader and overriding the findClassInternal method.

  • Configure Tomcat to use the advanced class loader.
    This is done in the corresponding webapp configuration file in the Tomcat conf/Catalina/hostname path with the following element:

    ...

Then, in eclipse, you can set your overall project to โ€œRequired projects on the build path,โ€ which makes it part of the class path.

This means that your advanced classloader should be able to look for another class:

  • either in a fixed predetermined path
  • or in a predefined class path.

I have not tested myself, but maybe this can give you an edge on this issue.


The comments suggest a much simpler noselasd solution using the GlobalNamingResources Tomcat Component .

However, frequently asked questions :

When you create a new Tomcat server in Eclipse, the New Server wizard assumes that it is unsafe to influence the current Tomcat installation behavior that this new server will use.

WTP may not affect the behavior of the installed Tomcat, using Tomcat's ability to run multiple server instances from the same installation. Thus, the default configuration for each new Tomcat segment you create will be a new instance of the Tomcat installation server associated with the Tomcat runtime selected in the wizard.
If you expect the new Tomcat server in Eclipse to run the same instance as the default batch files in your Tomcat installation start, you will probably be surprised if the Tomcat server in Eclipse does not behave as expected.

The configuration of your Tomcat server can be changed to run the same instance as your Tomcat installation.

You will find here to modify the server.xml file in WTP .

+1
source

All Articles