打包Java应用程序时,属性文件不包含在jar文件中 [英] Properties file isn't included in jar file when package Java application

查看:139
本文介绍了打包Java应用程序时,属性文件不包含在jar文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Netbeans开发了Java桌面应用程序。
在我的应用程序中,我使用了一些属性文件,然后将它放在Project文件夹下,以便我可以使用类似的代码访问它

I have developed Java desktop application using Netbeans. In my application, I used some properties files and I placed it under the Project folder so that I can access it by using code like that

 Properties props = new Properties();
 props.load(new FileInputStream("config.properties"));

但是当我将我的应用程序部署并打包到.jar文件时,我找不到属性文件是,我的应用程序无法读取属性文件中的值。

But when I deploy and package my application to .jar file, I can't find out where properties files are and my application can not read value from properties files.

如何修复该错误,我应该在哪里放置我的属性文件并加载它?

How can I fix that bug, and where should I place my properties file and load it?

推荐答案

将它放在 / src / resources / 下,然后像下面一样使用它。

Put it under /src/resources/, then use it like below.

ResourceBundle props = ResourceBundle.getBundle("resources.config");

NetBeans不包含项目目录下的文件。此外,您需要构建项目,以便让NetBeans将属性文件放在 / classes 目录中。然后你应该能够通过运行你的应用程序或只是一个特定的相关Java类来获取它。

NetBeans doesn't include the files under your project directory. Further, you need to build the project, in order to let NetBeans put the properties file inside your /classes directory. Then you should be able to pick it up, by running your application or just a particular related Java class.

干杯。

这篇关于打包Java应用程序时,属性文件不包含在jar文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆