Solved

Is it possible to read the properties file from a jar file?

Posted on 2014-12-25
3
312 Views
Last Modified: 2014-12-28
Hello,

I was just wondering if it was possible to read the properties from a jar?

I tried searching online; but I might have confused google with the keywords...

Appreciate any help on this!
0
Comment
Question by:Errang Genevre
3 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 100 total points
ID: 40517952
What do you mean by "properties", and what does this question have to do with Python? Is Python the language you are using to try and do the read?
0
 

Author Comment

by:Errang Genevre
ID: 40518064
Yes, sorry... forgot to mention that part.

I'm trying to see if its possible to use Python to read from a jar file; rather than having a Java class that just extracts the data from the jar file.
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 400 total points
ID: 40518108
Java jars are just specially formatted zip files.  So yes, you can open and read jars from python.  See the documentation on zipfile (https://docs.python.org/2/library/zipfile.html).

import zipfile
with zipfile.ZipFile("jython.jar", "r") as jar:
    with jar.open("jline/windowsbindings.properties", "r") as property_file:
        for line in property_file:
            print(line)

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SequenceInputStream example 3 21
jsp CRUD operations with and without prepared statement also hibernatge 1 27
Java class and jar 3 41
batch file or script 4 47
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question