打开 jar 内的文件
我有一个 ant 脚本,它可以做很多事情,但我被要求提供 jar,以便它可以作为应用程序运行。
我已经设法编写了 java 代码来以编程方式调用 ants,但在从代码中引用构建文件时遇到问题。
文件 buildFile = 新文件(BUILD_FILE);
其中 BUIlD_File 是我的 build.xml (存在于主目录中)。
当我将我的 proj 导出为 Runnable jar 时,它会抛出异常(找不到文件 build.xml)
即使我将 build.xml 文件添加到 jar 中,它仍然会抱怨,但如果我将 build.xml 文件放在 jar 所在的同一文件夹中然后就可以正常工作了。 (但我不想这样做)
谁能指导我如何确保当我导出为 jar 时 build.xml 文件添加到 jar 中以及如何在我的代码中引用该文件(jar 内)。
I have an ant script which does lots of stuff but I have been asked to provide jar so it can be run as an app.
I have managed to write the java code to invoke ants programatically but I am having the problem to refrence the build file from the code.
File buildFile = new File(BUILD_FILE);
where BUIlD_File is my build.xml (exists in the main directory).
When I export my proj as Runnable jar it throws an exception (File not found build.xml)
Even if I add the build.xml file into jar still it moans though if I put the build.xml file in the same folder where the jar is then it works fine. (But i dont wanna do this)
Can aynone guide me how can I make sure when I export as jar the build.xml file is added in jar and how can I refrence that file(inside jar) in my code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JVM 中运行的任何对象都可以获取 JAR 中任何资源/文件的 InputStream,如下所示:
在您的情况下,听起来 build.xml 不在包中,因此您应该能够使用:
Any Object running in the JVM can fetch an InputStream for any resource/file within the JAR as follows:
In your case, it sounds like build.xml isn't in a package so you should be able to use: