使用Java Eclipse创建具有.properties文件的Runnable JAR [英] Create Runnable JAR with .properties files using Java Eclipse

查看:150
本文介绍了使用Java Eclipse创建具有.properties文件的Runnable JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Eclipse的导出功能来构建一个可运行的JAR。一切正常,除了几个.properties文件,我在根目录下。



我将所有的.properties文件添加到Build Path中,它们显示在Order and Export但是,当我尝试运行导出,我收到以下错误:



无法读取JAR文件log4j.properties。原因:打开zip文件时出现错误
打开zip文件时出现错误
打开zip文件时出错



实际上创建了Runnable JAR文件,但是没有.properties文件。为什么尝试将.properties文件导出为ZIP文件?如何使这项工作?



Eclipse Build id:20090621-0832

解决方案

这是基于内存,但我相当确定属性文件不会自动从jar加载。这个想法是属性文件应该很容易修改。否则,这些值也可能只在一个类文件中。



如果您尝试从任何其他地方访问属性文件,这不应该是一个问题。



这也是为什么很少看到单独打包的jar文件。通常需要加载其他东西。



是否有理由需要这种行为?


I'm trying to build a runnable JAR using Eclipse's Export function. everything works fine except several .properties files I have under the root directory.

I added all the .properties files into Build Path, and they appears under 'Order and Export' tab in Java Build Path dialog.

However, when I try to run the Export, I got the following errors:

Could not read JAR file 'log4j.properties'. Reason: error in opening zip file error in opening zip file error in opening zip file

The Runnable JAR file is actually created, but with no .properties files in it. why does it try to export .properties files as ZIP files? how to make this work?

Eclipse Build id: 20090621-0832

解决方案

This is based on memory, but I'm fairly sure that properties files aren't automatically loaded from a jar. The idea is that the properties files should be easily modifiable. Otherwise, the values might as well just be in a class file.

If you tried to access a properties file from anywhere else, this shouldn't be a problem.

This is also why you seldom see jar files packaged alone. There is usually something else that needs to be loaded.

Is there a reason this behavior is necessary?

这篇关于使用Java Eclipse创建具有.properties文件的Runnable JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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