为什么要在包上使用许多子项目和依赖项?
在我的职业生涯中,我主要从事中小型 Java 项目。我最近在eclipse中看到一个由30个项目组成的庞大项目。我真的不明白创建许多小项目然后维护项目间依赖关系的概念。我们什么时候更喜欢这样做而不是简单地将东西整理成包?
我猜这是一个专家的事情(主要是使用 Ant)。我也一直在阅读 Maven 的模块概念——我在网上看到了一些链接,建议在父模块下为 Web、dao 和服务层创建不同的模块。这真的是常见/最佳实践吗?
无论有没有 Maven,这样的划分真的会让生活变得更轻松吗?将所有内容都放在一个项目中,并为不同层提供明确定义的包结构,这不是更紧凑吗?
I’ve mostly in my career worked in small or mid-sized java projects. I recently saw a huge project comprising of 30 projects in eclipse. I don’t really get concept of creating many small projects and then maintain inter-project dependencies. When do we prefer this over simply organizing stuff in packages?
I guessed it’s a maven thing (have mostly been using Ant). I’ve been reading up on Maven’s concept of modules as well – I saw some links on net recommending creation of different modules for web, dao and service layers under a parent module. Is it really a common/best practice?
With or without maven – does such division really makes life easier? Isn’t it more compact to have everything in a single project with well-defined packages structure for different layers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当需要时,将项目拆分为 API、实现、Web 等组件是很常见的。大项目就是这样:大。
保持组件独立有好处”
做所有相同的事情,但是当这些分界线被明确定义时,确定什么会发生在哪里以及为什么会变得更容易。
您可以在一个巨大的项目中 在项目上,但是当你处理数十万行代码,有时甚至数百万行,将这些内容分解可以节省巨大的麻烦。
It's common to split up projects into API, implementation, web, etc. components–when there's a need to do so. Large projects are just that: large.
There are benefits to keeping components separate"
You can do all the same stuff with one giant project, but it's more difficult to determine what goes where, and why. Life is easier when those lines of demarcation are clearly defined.
How much easier depends on the project, but when you're dealing with hundreds of thousands of lines of code, occasionally millions, breaking that stuff up saves huge headaches.
为什么选择在maven中创建单独的模块?为您的发展提供帮助。确实没有其他原因。
您可能想要创建单独的模块的原因有很多:
您选择分解为模块的原因与分解为包的原因相同,但在更高的级别上,是在一组包中。
30确实显得太多了。但这可能有充分的理由。由您和您的项目决定模块数量的正确级别。
就我个人而言,我尽量不要过度分裂,除非有充分的理由这样做。
[*] Tangle:混乱,描述了包之间的链接。包A使用B,B使用C,C同时使用A和B。这对理解没有帮助。
Why choose to create a separate module in maven? To help you with your development. There really is no other reason.
The are a number of different reasons why you may want to create a separate module:
You choose to break up into modules for the same reasons as you would for separating into packages, but at a higher level, at a group of packages.
30 does seem excessive. But there may be good reasons for it. It's up to you and your project to decide what is the right level for the number of modules.
Personally, I try not to split excessively, unless there is a very good reason to do so.
[*] Tangle: mess which describes the links between packages. Package A uses B, which uses C, which uses both A and B. Something which doesn't help understanding.
我认为过度的模块化类似于过度工程。我认为最好的路线是从一个模块/项目开始,并一直坚持下去,直到每个参与其中的人都清楚地意识到,现有模块的一部分将受益于提取到自己的模块中。是的,这意味着那时需要额外的工作,但对我来说,我宁愿先做这些工作,也不愿在我的构建和开发环境方面无休止地与不必要的复杂性作斗争,以获得从未真正实现的好处。
不幸的是,在项目开始时,甚至在编写一行代码之前,似乎存在一种模块化程度的趋势。
I think excessive modularisation is akin to over engineering. The best route in my opinion is to start with one module/project and keep with that until such point as it becomes obvious to everyone involved that part of this existing module would benefit from being extracted into its own module. Yes, that means extra work at that point, but for me I'd rather do the work then than endlessly battle with unneeded complexity, in terms of my builds and my development environment, for benefits which are never actually realised.
Unfortunately there seems to be a tendency at the start of a projects to modularise to the nth degree before even a single line of code is written.
这还有另一个优点..如果我必须部署在“选定的”组件上,我不会浪费时间和资源来部署我不需要的依赖项。
there is another advantage to this.. if i have to deploy on 'selected' components i dont waste time and resources deploying dependencies that I dont need.