Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I access a config file inside the jar?
    text
    copied!<p>I'm using <a href="http://flatpack.sourceforge.net/" rel="nofollow noreferrer">FlatPack</a> to parse and load data from flat files. This requires loading a config file that stores mappings of the columns of the flat file.</p> <p>I have a constant to define the location of the mapping file:</p> <pre><code>private static final String MAPPING_FILE = "src/com/company/config/Maping.pzmap.xml"; </code></pre> <p>I have a parse(File dataFile) method that actually does the parsing:</p> <pre><code>private void parse(File dataFile) throws FileNotFoundException, SQLException { Parser parser; log.info("Parsing " + dataFile.getName()); FileReader mappingFileReader = new FileReader(MAPPING_FILE); FileReader dataFileReader = new FileReader(dataFile); parser = DefaultParserFactory.getInstance().newFixedLengthParser(mappingFileReader, dataFileReader); parser.setHandlingShortLines(true); DataSet dataSet = parser.parse(); //process the data } </code></pre> <p>When I jar up everything and run it as a jar - it bombs out on <code>FileReader mappingFileReader = new FileReader(MAPPING_FILE);</code> with a <code>FileNotFoundException</code>. That file is inside the jar though.</p> <p>How do I get to it?</p> <p>I've looked at <a href="https://stackoverflow.com/questions/600146/run-exe-which-is-packaged-inside-jar">this question</a> and <a href="https://stackoverflow.com/questions/463972/creating-a-new-file-using-an-existing-file-within-a-jar">this question</a> about accessing files inside jars and they both recommend temporarily extracting the file. I don't want to do that though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload