[英]How can one deploy common JavaScript and images to two different EARs while not having to maintain two versions of each file
I have a Struts web app deployed to an EAR that has some pretty extensive JavaScript. 我有一个Struts Web应用程序部署到具有一些相当广泛的JavaScript的EAR。 I now need to create a new web app that will be deployed to a new EAR but will probably need to share most if not all of the JavaScript and some images from the first application.
我现在需要创建一个新的Web应用程序,该应用程序将部署到新的EAR,但可能需要共享(如果不是全部的话)大多数JavaScript和第一个应用程序中的一些图像。 What's the best way to avoid code duplication so I don't have to put a copy of each JavaScript file in each EAR in my development environment?
避免代码重复的最佳方法是什么,这样我就不必在开发环境中的每个EAR中放置每个JavaScript文件的副本了?
You could maintain the Javascript in a separate .jar library and serve it as a resource, not as a static file. 您可以将Javascript维护在单独的.jar库中,并将其作为资源而不是静态文件使用。 That way the JS content would be a regular dependency in your project setup.
这样,JS内容将成为项目设置中的常规依赖项。 Unfortunately there isn't a straightforward universal way to do this because you need at the very least a servlet that will send the file from the .jar.
不幸的是,并没有一种直接通用的方法来执行此操作,因为您至少需要一个Servlet,它将从.jar发送文件。 (Depending on your web framework you might already have this available.)
(取决于您的Web框架,您可能已经可以使用此功能。)
This also has some performance implications, but for a line of business application you probably don't need to optimize the load time of your internal Javascripts all that heavily. 这也对性能有一些影响,但是对于一系列业务应用程序,您可能不需要大量优化内部Javascript的加载时间。
Another alternative would be doing this at the source control level, using something like Git submodules . 另一种选择是在源代码控制级别使用Git子模块进行此操作 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.