ANT 生成的 jar:是命名空间问题吗?
我有一个带有 ANT 构建文件的 Eclipse-Java-项目。此构建文件导出项目的 jar 而不编译它。所以我只导出源。
<target name="jar">
<mkdir dir="/jar"/>
<jar destfile="/jar/my_test_jarfile.jar" basedir="/src" />
</target>
我在另一个 eclipse java 项目中使用这个生成的 jar,并在项目的 build-path-settings 中设置 jar 的路径。问题是 eclipse 说它无法解析 jar 的导入类的名称空间。 如果我通过右键单击项目然后“导出”并将 jar 放入其他项目的构建路径来手动导出 jar,则一切正常并且没有错误。所以现在的问题是,我做错了什么?
I have a Eclipse-Java-Project with an ANT-build-file. This build file exports a jar of the project without compiling it. So I only export the sources.
<target name="jar">
<mkdir dir="/jar"/>
<jar destfile="/jar/my_test_jarfile.jar" basedir="/src" />
</target>
I use this generated jar in another eclipse java project and set the path to the jar in the build-path-settings of the project. The problem is that eclipse says it cannot resolve the namespace of the imported classes of the jar.
If I export the jar manually by right clicking on the project and then "Export" and putting the jar to the build path of the other project, everything works fine and there are no errors. So the question is now, what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我的解决方案。看来必须先编译源码,然后打包成jar。我不保证这个 jar 与您右键单击并导出等操作时从 eclipse 获得的 jar 完全相同。
但它对我有用,不再有命名空间错误。所以这是我的 ant 目标的最低版本:
So here is my solution. It seems that you have to compile the source first and then pack it into a jar. I don't give a guarantee that this jar is exactly the same like the one you get from eclipse when you do the right click thing and export etc.
But it works for me, there are no namespace errors any longer. so here is a minimum version of my ant targets: