4

I need to create 2 war applications deployed on tomcat server. One of the applications have the exact same logic and code as the other application but with added changes to the view and controllers.

Then App1 and App2 will have the same code to access data and I don't want to duplicate code. My idea is 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 the best for performance?

1
  • Voted up, I don't really understand the downvote, it was a bit confusing for me too when I was beginner in web based technologies. Feb 4, 2013 at 9:36

3 Answers 3

2

Option 1

If you are sharing code (and it's a big piece of code, which drives you crazy while uploading the war-files) it may be an option to create a jar containing the code and add the jar file to tomcats library-folder, which is

${CATALINA_BASE}/lib/

Note that this is usually not something you want to do lightly, because that jar file will be available to ALL war-files on the tomcat, creating possible namespace-problems.

Option 2

If sharing the code with all the projects on the application-server is not an option you'll have to add the jar-file to the projects and add it into it's classpath (which happens automatically within eclipse if you add the jar into

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

Preformance-wise this doesn't really make a difference since tomcat will load the class-files, which are not very big. The instances might be, but the type of deployment doesn't really have an impact upon instances.

2

If you want to use the same classes for both projects just simple create one .jar file which will contain those classes. Then add that .jar into your web projects' classpath and use it in both.

1

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

If you used maven for building your wars, it would be easier to build a project hierarchy.

something like:

parent
 |_common(jar)
 |_war1
 |_war2 
1
  • Got any links or tips on how to do this?
    – Dennis
    Sep 25, 2013 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.