Reputation: 3157
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
Upvotes: 2
Views: 23299
Reputation: 11423
Instead of using the Export wizard to create a "Runnable JAR", you can use the wizard to create a (plain) "JAR" file. In this wizard, you can select which specific files should be added to the JAR file.
If you specify a main class in the wizard, the resulting JAR file will also be runnable (by double-clicking or with java -jar myapp.jar
).
Upvotes: 0
Reputation: 582
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?
Upvotes: 5
Reputation: 189856
Here's what I do and it works reliably:
<copy>
task declared before the <jar>
task in the same target.I am not sure what the Eclipse Export utility does but you might try looking at ant, as it may give you more control over the build process.
Upvotes: 1
Reputation: 2907
jar files are pack and/or compressed as ZIP files, only file extension changes.
When all properties are shown in Export wizard, they are selected? When you open the jar file, there some file? *.class, META-INF, ... ?
[]'s,
And Past
Upvotes: 0