我们是否正在走向类似于 dll 地狱的 java 平台中的 jar 地狱?
昨晚我试图发布一个简单的教程来使用堆栈构建应用程序 - Spring (2.5) + JPA (1.0) + Hibernate(第一次下载,所以不知道使用哪个版本)。不幸的是,我不想使用 Maven,因为目标参与者使用 ANT 构建。像往常一样,点击搜索引擎并以某种方式获得了 appcontext、persistence.xml 和 java 类中的步骤。当我开始获取所需的库时,我就迷失在 JAR 地狱中了。幸运的是,Spring 方面没有太大问题,因为所有依赖的 JAR 都为我的 Spring 2.5.6 打包在一起。
当谈到休眠时,我不知道首先要包含哪些所有 Jars。在下一个挑战中,不知道每个要添加哪个版本。
最后我让整个事情开始工作,但是再次进入这个 JAR 地狱看起来很可怕,除非我被带入 Maven 天堂。
由于有大量的拦截器和编织,对于传统的 Java 程序员来说,它变得越来越复杂,他们曾经喜欢 Java 主要是因为我的代码正在做什么有很大的透明度。
我的思考过程正确吗?
Last night I was trying to put a simple tutorial to build an application using the stack - Spring (2.5) + JPA (1.0) + Hibernate (downloading for first time, so didn't know which version to use). Unfortunately I didnt want to use Maven as the target participants were on ANT build. As usual hit the search engine and got somehow the steps in the appcontext, persistence.xml and in the java classes. The moment I started getting required libraries, I lost in the JAR hell. Luckily, not much of a problem on the Spring side as all the dependent JARs are packaged together for my Spring 2.5.6.
When it came to hibernate, I had no clue which all Jars to be included on the first place. On the next challenge, didn't know which version for each to add.
Finally I got the whole thing working, but it looks so scary to enter this JAR hell again unless I am taken through Maven heaven.
With lots of interceptors and weaving, it is becoming more complicated for the conventional Java programmer who once liked Java primarily for lots of transparency on what my code is doing.
Am I right in the thought process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Ant 时您仍然可以进行依赖管理,请使用 Ivy。
请参阅详细教程
还有一件事,如果您指的是具有完整 Spring 2.5.6 捆绑包的 spring.jar,我强烈建议不要使用它,您可能不需要超过其中包含的 20% 的库。 (花点时间找出您确实需要哪些库,然后只选择那些库。)
此外,如果可以的话,请考虑使用 Spring 3,以及 Hibernate,如果您可以自由选择版本,我会选择最新的。
You can still have dependency management while using Ant, use Ivy.
See a detailed tutorial here for more or less exactly the stack you want to use. (Doesn't include Hibernate but I guess you can find how to add that pretty quickly)
And one more thing, if you are referring to the spring.jar which has the full Spring 2.5.6 bundle, I strongly suggest not to use it, you probably need not more than 20% of the libraries included in it. (Take the time to discover exactly which libraries you do need and only pick those.)
Also, consider using Spring 3 if you can, as well as Hibernate, if you are free to pick a version, I'd go for the latest.
我之前使用过其他JPA实现,但今年我第一次使用Hibernate。当然,在 jar 依赖关系方面它比其他的更复杂,但是在 入门指南,位于 第 1 章,位于 <一个href="http://docs.jboss.org/hibernate/core/3.6/quickstart/en-US/html/hibernate-gsg-obtain.html#hibernate-gsg-setup-releaseBundle" rel="nofollow">获取Hibernate 我找到了有关我需要哪些 jar 以及原因的详细信息。
后来我确实遇到了 jar hell 问题,不是因为不知道使用哪些 jar,而是因为我们处于一个非常大的项目中,而其他子项目已经在使用旧版本的 Hibernate 类,这给我带来了很多麻烦在运行时,我花了几天时间来诊断和修复。
我认为这暂时是现实,Maven 等工具或 OSGi 等框架试图缓解这个问题。
也许我们最大的希望是Jigsaw 项目打算在未来成为 JDK 8 的一部分,并试图解决我们目前遇到的Java模块化问题。它就像一个带有类固醇的 OSGi,并且内置于 JDK 本身中。
但在此之前,我只能告诉你一句威斯顿·丘吉尔的名言
I had used other JPA implementations before, but I used Hibernate for the first time this year. Certainly it is more complicated than others in terms of jar dependencies, but in the Getting Started Guide, in Chapter 1, under Obtaining Hibernate I found details on which jars I needed and why.
I did suffer of jar hell problems later on, not because of not knowing which jars to use, but because we are in a really big probject, and other subprojects were already using older versions of Hibernate classes, and this caused me a lot of trouble at runtime and it took me several days to diagnose and fix.
I think this is a reality for the time being, and tools like Maven or frameworks like OSGi attempt to alleviate the problem.
Perhaps the biggest hope we have is Project Jigsaw intended to be part of JDK 8 in the future and which attempts to solve the Java modularity problems we currently have. It will be like a OSGi with steroids, and built in the JDK itself.
But before that happens, all I can tell you is a famous quote by Wiston Churchill
这是 Grails 解决的问题之一 - 通过捆绑一组特定的可用 jar(Spring、Hibernate 等)一起并随着 Grails 的发展升级这些 jar。
This is one of the issues that Grails addresses - by bundling a specific set of jars (Spring, Hibernate, etc) that work together and upgrading those jars as Grails evolves.