OS X 上的应用程序包不起作用,文件寻址问题
我的应用程序需要 XML 文件才能工作,如果没有该文件,它甚至无法启动。为什么我将我的应用程序捆绑为 JAR 文件,只要 XML 文件与 JAR 文件放在同一目录中,它就可以正常工作。
当我将项目导出为 OS X 应用程序包时,该应用程序无法运行。如果我将 XML 文件复制到应用程序包所在的同一目录中,它就可以工作。
因此,我非常确定从 Java 代码中访问 XML 文件只是一个小解决问题。我想将 XML 文件放入应用程序包中。简单地将其复制到 JAR 文件所在的同一目录中是行不通的。
该文件,或者更好的是,文件的地址如下:doc = sax.build("file.xml");
,并且直接位于我的项目文件夹中。 我正在使用 Eclipse,并将我的项目直接从 Eclipse 导出为应用程序包。 我还使用 OS X Jar Bundler 进行了尝试,得到了相同的结果。
那么,如何正确寻址我的文件,以便将它们放入应用程序包中?
任何帮助表示赞赏!非常感谢!
My application requires a XML file to work and it doesn't even start without the file. Why I bundle my app as a JAR file it works fine as long as the XML file is placed in the same directory as the JAR file.
When I'm exporting the project as an OS X application package, the application does not work. If I copy the XML file in the same directory where the application package is, it works.
So I'm pretty sure that it is a minor addressing problem to access the XML file from within my Java code. I'd like to put the XML file into the application package. Simply copying it in the same directory where the JAR file is does not work.
The file, or better the files are addressed like this: doc = sax.build("file.xml");
and are located directly in my project folder.
I'm working with Eclipse and I export my project directly from Eclipse as an application bundle.
I also tried it with the OS X Jar Bundler, which delivers the same result.
So, how do I address my files correctly, so that I can place them into the application bundle?
Any help is appreciated! Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您很可能将其作为物理文件读取,该文件需要位于当前工作目录中。
您是否考虑过将其作为资源读取,而不是允许通过类路径找到它?
You are most likely reading it in as a physical file, which needs to be located in the current working directory.
Have you considered reading it in as a resource instead which allows it to be found via the classpath?