2 war exchange codes

I need to create 2 military applications deployed on a tomcat server. One of the applications has the same logic and code as the other application, but with added changes in the presentation and controllers.

Then App1 and App2 will have the same code to access the data, and I do not want to duplicate the code. My idea is to create 2 WARs, and these WAR files should use a library or other project (I don't know) that has access to the database.

Which solution is best for performance?

+4
source share
3 answers

Option 1

If you use the code (and this is a large piece of code that drives you crazy when loading military files), it may be possible to create a jar containing the code and add the jar file to the tomcats library folder, which equals

  $ {CATALINA_BASE} / lib / 

Please note that this is usually not what you want to do easily, because this jar file will be available for ALL military files on tomcat, creating possible namespace problems.

Option 2

If sharing code with all projects on the application server is not an option, you will have to add the jar file to the projects and add it to its class path (which happens automatically in the eclipse if you add the jar to

  $ {PROJECT_ROOT} / WebContent / WEB-INF / lib 
)

Accordingly, this does not really matter, since tomcat will load class files that are not very large. There may be instances, but the type of deployment does not really affect instances.

+2
source

If you want to use the same classes for both projects, just create one .jar file that will contain these classes. Then add this .jar to your web project classpath and use it in both.

+2
source

You can extract the common part and make it like a jar. And then two wars use this jar as a library.

If you used maven to build your wars, it would be easier to create a hierarchy of projects.

sort of:

 parent |_common(jar) |_war1 |_war2 
+1
source

All Articles