简体   繁体   English

如何将通用的JavaScript和图像部署到两个不同的EAR,而又不必维护每个文件的两个版本

[英]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.

相关问题 如何配置Maven以构建两个版本的工件,每个版本用于不同的目标JRE - How to configure Maven to build two versions of an artifact, each one for a different target JRE 如何在Wildfly中设置两只耳朵的部署顺序 - How to set deployment order of two ears in Wildfly 如何在 OpenShift 中同时部署两个版本的微服务? - How can I deploy two versions of a microservice at the same time in OpenShift? 在一个 web 应用程序中从两场战争中构建两只耳朵 - Building two ears from two wars in one webapp 两个不同的jar x,y依赖于z的不同版本。 用户如何在应用程序中同时拥有x,y? - Two different jars x,y having dependency on different versions of z. How user can have both x,y in his application? 使用Maven,如何使用一个不同的.java文件构建两个版本的Java项目? - With Maven how do I build two versions of a Java project with just one different .java file? 如何使用maven构建两个EAR,一个模块已打包,另一个已解压缩? - How to build two EARs using maven, one with modules packed and the other unpacked? Maven:可以合并两只耳朵吗? - Maven : is it possible to merge two ears? 两只耳朵在野蝇中的部署顺序 - Deployment order of two ears in wildfly 如何让 Mapper 从具有公共列的两个不同文件中获取输入? - How make Mapper to take inputs from two different files having common column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM