Jar dependency - Application server classpath vs adding it to the application war itself

眉间皱痕 提交于 2019-12-23 18:08:49

问题


We have an installation of Weblogic 10.3.6. An application running on it needs the following jar

com.oracle.ws.http_client_1.3.0.0.jar

The above jar is located in the server bundle Oracle\Middleware\modules\com.oracle.ws.http_client_1.3.0.0.jar

What's the right approach? Should this jar (appears to be a system library written by Oracle, not found on mvnrepository site) be added to the server classpath or should I add it to the application archive (war)?? Thanks.

Update: Also the above jar comes bundled with Weblogic (not added to classpath by default though) and is not found in maven public repo. So, this is not meant to be added to the application directly?


回答1:


  1. If the jar is part of the application server environment/build I would not add it to the war/ear file. It should be availble through out all the env DIT/UAT/PROD (envs need to be consistent with prod). Also when the app serever fixes are applied or server is upgaded we will be using the lastest jar.

  2. In other cases(external) it would be best to package it in war in order to avoid issues while migrating from env to env.




回答2:


Best place to place JAR files and other dependencies is to pack it within the WAR rather than keeping into system classpath. By doing this you have following advantages.

  1. WAR file is self-sustainable and robust without any dependency on it's container.
  2. Same WAR file, without any packaging change can be deployed to DEV, IT, QA, Demo, Test, Production, blah, blah or any environment present.
  3. No issues between system & webapp classloaders.

There may be debates as by packing everything in the WAR file may end up increasing the WAR file size significantly. But it is really frustrating when there is a funny production error out of no where in middle of night just because you missed to update http_client_1.3.0.0.jar to http_client_1.4.x.y.jar and others plainly state that exact same WAR file was working perfectly in testing environment.

From my experience, I believe consistency of a WAR file is an important aspect. And, hence, suggest you to pack every required JAR file into the WAR, until and unless the JAR is provided implicitly by the container.

  • Disk space cost per GB = $1
  • Effort to resolve inconsistency issue = $50
  • Giving up midnight sleep to resolve a crazy issue = priceless

:)




回答3:


It depends. When you are inserting dependency inside the classpath it's loaded by default classloader - then e.g. all enums and singletons are initialized by this default classloader. Depending on server's configuration all applications would share those instances or they might get their own independently instantiated.

Additionally when you add dependency to the class path it becomes available to all applications on server, whether they need it or not.

If you got only one application, it wouldn't make a difference. If there is more, it would be safer to add JAR to the application unless you explicitly want to make this library (and this particular version) globally available on server for all deployed WARs to use.

EDIT:

Apparently you can be sure that each application would have its own instances of enums and singletons as described here. So your only issue in classpath approach would be if different applications would require different versions of the same library.



来源:https://stackoverflow.com/questions/26371010/jar-dependency-application-server-classpath-vs-adding-it-to-the-application-wa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!