可重用的架构代码管理
我们的代码是 Java 和 Javascript(AJAX 库)。我们在现有库周围有包装器/可重用代码来执行日常任务,例如数据库连接、会话管理、日志记录、休眠设置、基本结构、一些可重用多租户代码等。从 javascript 端来看,我们有页面初始值设定项、UI 布局组件,自定义js对象,以及一些我们自己的逻辑。
我们有多个项目可以重用这些代码,但同时,这些代码也随着应用程序一起发展。因此,如果我们找到一种通用的方法来做到这一点,我们可以将其移动到框架代码中,让其他项目也从中受益。如果/当我们在基本代码中发现错误时,我们可以在一个地方修复它并提交,所有其他项目将接受更改(而不是每个人都在本地进行更改)。
如果它只是 java 文件,我们可以将其保留为一个单独的项目,并将其作为依赖模块包含在 eclipse/maven 中,并在需要时将其作为 jar 包含在内。这部分很容易处理,但是现在我们的代码中还有可重用的javascript,它不能完全被jar(ed)。我们想要一些关于如何布局代码的建议,这样我们就可以通过 maven(部署时间)和 eclipse(开发时间)重用它,而不需要经历太多的麻烦。
在写这篇文章之前,我确实在 stackoverflow 上看到了一些文章,其中确实讨论了很棒的可重用代码和方法,但不完全是如何使用 svn、maven、eclipse 等管理它们。
链接它们,以供参考。
- 一些可重用代码的架构
- 如何使代码可重用? ->从理论角度来看,这是一篇很棒的文章,但没有提供管理方面的建议。
- 如何索引并提供可重用代码?
在我们的一些旧项目中,我们维护了 ant 文件,它将文件从基地位置复制到最终战争,因此一切都可用。但随着项目的发展,即使是一个简单的检查,我们也必须重建整个战争并部署到开发人员的机器上进行测试。每次都要花掉5分钟。
那么问题来了,有没有什么repository模式、eclipse项目布局思路、打包风格可以帮助我们解决这个问题呢?
Our code is in Java and Javascript (AJAX libraries). We have wrappers/reusable code around the existing libraries to perform mundane tasks like, db connections, session management, logging, hibernate settings, base structure, some reusable multitenancy code etc.. From the javascript end, we have page initializers, UI layout components, custom js objects, and some of our own logic.
We have multiple projects where this code can be reused, but at the same time, this code is evolving along with the application. So if we find a common way to do it, we can move it to the framework code and let other projects also benefit out of it. If/when we find a bug in the base code, we can fix it in one place and commit and all the other projects will pick up the change (rather than everyone making the changes locally).
If it's just java files, we can keep it as a separate project, and include it as a dependent module in eclipse/maven and have it included as a jar, as and when needed. This part is easy to handle, but now we also have reusable javascript in the code, which cannot exactly be jar(ed). We want some suggestions on how the code should be laid out, so we can reuse it via maven (deployment time) and via eclipse (development time), without going thru too many hoops.
Before writing this, I did come across some articles on stackoverflow, which do talk about reusable code and methodologies which are great, but not exactly how to manage them using svn, maven, eclipse etc..
Linking them, for reference.
- Architecture of some reusable code
- How do you make code reusable? -> This is a great article from a theory stand point, but no tips on management.
- How do I index and make available reusable code?
In some of our old projects, we maintained ant files, which would copy files from base locations to the final war, so everything is available. But over the period of time as the project grew, even for a simple check, we had to rebuild the whole war and deploy to test on the developers machine. Which took away 5 minutes every time.
So the question is, are there any repository patterns, eclipse project layout ideas, packaging styles, which can help us resolve this issue ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用面向组件的 java web 框架来完成此类任务。我立刻想到了威克特。 (但是 JSF、Tapestry 等也同样可以很好地工作)
在 wicket 中,一切都是组件,并且组件可以与行为一起打包(可能包括 javascript、css 等),
因此您将拥有一个公共项目,在其中维护可重用的 java 和 javascript代码。
好处是显而易见的,这几乎正是您所要求的。另一方面,缺点主要是 javascript 和 css 内容位于 jar 中,并将由应用程序服务器而不是静态 Web 服务器或 CDN 提供服务。
肖恩
I would suggest using a Component oriented java web framework for such tasks. Wicket immediately comes to mind. (But JSF, Tapestry etc will work equally well)
In wicket, everything is a component and components can be packaged with behaviors (which may include javascript, css etc)
So you'd have a commons - project where you maintain reuseable java and javascript code.
The benefits are obvious, it's pretty much exactly what you have been asking for. The drawbacks, on the other hand are mainly that javascript and css content is inside your jars and will be served by the app server rather than a static web server or CDN.
Sean