How do I access a config file inside the jar?

前端 未结 4 896
暗喜
暗喜 2020-11-29 12:30

I\'m using FlatPack to parse and load data from flat files. This requires loading a config file that stores mappings of the columns of the flat file.

I have a const

相关标签:
4条回答
  • 2020-11-29 12:55

    If I remember correctly, getResourceAsStream() can behave differently depending on which web server your webapp is deployed, for instance I think it can be a problem when deployed as a war on a Websphere instance. But I'm not sure if this applies to you.

    But I'm not sure you're trying to solve the "proper" problem : if it's a config file, that means is data dependant right ? Not code dependant ( your jar ) ? When the flat file will change, your config file will need to change as well, right ? If this is true, it sounds like the config should be better stored elsewhere, or even passed as a parameter to your jar.

    But maybe I haven't fully understood your problem...

    0 讨论(0)
  • 2020-11-29 13:01

    Use Apache Commons Configuration, then you can read/write XML, auto update, find config file in path or jar, without a lot of hassles.

    0 讨论(0)
  • 2020-11-29 13:05

    I think it is solved just here:

    http://www.velocityreviews.com/forums/t129474-beginner-question-how-to-access-an-xml-file-inside-a-jar-without-extracting-it.html

    0 讨论(0)
  • 2020-11-29 13:15

    if it's inside a JAR, it's not a File, generally speaking. You should load the data using Class.getResourceAsStream(String), or something similar.

    0 讨论(0)
提交回复
热议问题