2

I have created a Data Access layer which is responsible to retrieve data from the database using plain SQL query. My tomcat contains two web projects. Both projects contain same copy of Data Access layer.

Web Project1 (WP1)
   |----DataAccess layer

Web Project2 (WP2)
   |----DataAccess layer

I would like to separate Data Access layer from web project, so I don't need to maintain multiple copies.

WP1 -- WP2
  |             |
DataAccess layer

Is it the best practice to make the Data Access layer as JAR file and put it inside Tomcat shared lib folder?

Thanks, MFH

MFH
  • 357
  • 3
  • 17

1 Answers1

0

I won't say that doing so is dangerous but I definitely won't consider this solution as a "best practice" : sharing a library across all the web application will increase the probability that one of them will run into a classpath conflict.

For instance, suppose that you deploy another web application in which you're using (knowingly or not) a class that is duplicated (several classes with the same exact full qualified name), given that the shared libraries are loaded before the application specific libraries, you could end up using another class than the one expected. In the best scenarios, you'll figure it out quite easily but still that would have made you loose some time. In the worst scenario, your application won't behave as expected.

From my personal experience, I've seen this happening in the past : some applications were referring to a shared lib-1.0.jar and some others were deployed with a application-specific lib-2.0.jar (which had slightly evolved).

Besides, in your case, it won't cause a maintenance havoc : just adapt the deployment procedure from both of your web application to add the concerned library as a dependency (if you're using tools such as Maven or Ant, it's a piece of cake).

kyiu
  • 1,926
  • 1
  • 24
  • 30