解决 Virgo 与 jar 包的依赖关系
我正在尝试将许多罐子包装为捆绑包,我希望其他捆绑包能够依赖它们。使用 Spring dm Server,这曾经非常简单,只需将 jar 文件添加到新的捆绑项目中,导出所有类,并确保 jar 文件位于构建路径和类路径上。
这是我正在尝试做的事情(以及我失败的地方)的一个简单、规范的示例:
以 Joda Time 为例,我希望将其打包在一起,以便我可以将其作为依赖项共享。首先,我创建一个包来保存 jar:
- 创建一个新的包项目 Eclipse (Indigo Java EE)
- 在项目根目录中创建一个文件夹“lib”
- 将 joda-time-1.6.1.jar 添加到“lib”文件夹
- 添加 lib /joda-time-1.6.1.jar 到构建路径
更新 src/META-INF/MANIFEST.MF 以导出所有类:
清单版本:1.0 捆绑版本:1.0.0 捆绑包名称: joda-time 捆绑清单版本:2 捆绑符号名称:org.joda.time 捆绑包类路径:lib/joda-time-1.6.1.jar, 。 导出包:org.joda.time, org.joda.time.base, org.joda.time.chrono, org.joda.time.convert, org.joda.time.field, org.joda.time.format, org.joda.time.tz
现在,我们希望在我们创建的一些新包中使用它:
- 在 Eclipse (Indigo Java EE) 中创建一个新的包项目” MyDepTest"
编辑 src/META-INF/MANIFEST.MF 以导入 org.joda.time:
清单版本:1.0 捆绑版本:1.0.0 捆绑包名称:MyDepTest 捆绑清单版本:2 捆绑符号名称:com.foo.deptest 导入包:org.joda.time 导入包:org.joda.time;version="[1.0.0,1.0.0]"
将 org.joda.time 包添加到项目引用中 以便 Eclipse 可以解析依赖项
编写类:
package com.foo.deptest; 导入 org.joda.time.DateTime; 公共类 SimpleDepTest { 公共 SimpleDepTest (){ DateTime dt = new DateTime(); } }
现在,org.joda.time.DateTime
应该可以解析,但 Eclipse 在 org.joda
无法解析导入org.joda
我哪里出错了?如何将 jar 包装为包以便我可以使用其他包中的类?
I'm trying to wrap a number of jars as bundles that I want other bundles to be able to depend on. With Spring dm Server, this used to be as simple as adding a jar file to a new bundle project, exporting all the classes, and ensuring the jar file was on the build and class paths.
Here's a simple, canonical example of what I'm trying to do (and where I'm failing):
Take, for instance, Joda Time, I'd like this in a bundle so I can share it as a dependency. First, I create a bundle to hold the jar:
- Create a new bundle project Eclipse (Indigo Java EE)
- Create a folder "lib" in the project root
- Add joda-time-1.6.1.jar to the "lib" folder
- Add lib/joda-time-1.6.1.jar to the build path
Update src/META-INF/MANIFEST.MF to export all of the classes:
Manifest-Version: 1.0 Bundle-Version: 1.0.0 Bundle-Name: joda-time Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.joda.time Bundle-ClassPath: lib/joda-time-1.6.1.jar, . Export-Package: org.joda.time, org.joda.time.base, org.joda.time.chrono, org.joda.time.convert, org.joda.time.field, org.joda.time.format, org.joda.time.tz
Now, we want to use this in some new bundle we've created:
- Create a new bundle project in Eclipse (Indigo Java EE) "MyDepTest"
Edit src/META-INF/MANIFEST.MF to import org.joda.time:
Manifest-Version: 1.0 Bundle-Version: 1.0.0 Bundle-Name: MyDepTest Bundle-ManifestVersion: 2 Bundle-SymbolicName: com.foo.deptest Import-Package: org.joda.time Import-Bundle: org.joda.time;version="[1.0.0,1.0.0]"
Add the org.joda.time bundle to the project references so Eclipse can resolve the depenencies
Write the class:
package com.foo.deptest; import org.joda.time.DateTime; public class SimpleDepTest { public SimpleDepTest (){ DateTime dt = new DateTime(); } }
Now, org.joda.time.DateTime
should resolve, but Eclipse indicates the following error with a red underline on org.joda
The import org.joda cannot be resolved
Where have I gone wrong? How do I wrap a jar as a bundle so that I can use the classes in other bundles?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,将 jar 添加到类路径是不够的,我们还需要确保它是构建路径的一部分。这是在构建配置对话框中完成的:
It turns out it's not sufficient to add the jar to the classpath, we also need to make sure it's part of the build path. This is done in the build configuration dialog: