Referencing java resource files for cold fusion

Posted by Chimeara on Stack Overflow See other posts from Stack Overflow or by Chimeara
Published on 2014-06-02T00:47:45Z Indexed on 2014/06/02 3:26 UTC
Read the original article Hit count: 150

I am using a .Jar file containing a .properties file in my CF code, however it seems unable to find the .properties file when run from CF.

My java code is:

        String key ="";
    String value ="";

    try {
        File file = new File("src/test.properties");
        FileInputStream fileInput = new FileInputStream(file);
        Properties properties = new Properties();
        properties.load(fileInput);
        fileInput.close();

        Enumeration enuKeys = properties.keys();
        while (enuKeys.hasMoreElements()) {
            key = (String) enuKeys.nextElement();
            value = properties.getProperty(key);
            //System.out.println(key + ": " + value);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        key ="error";
    } catch (IOException e) {
        e.printStackTrace();
        key ="error";
    }

    return(key + ": " + value);

I have my test.properties file in the project src folder, and make sure it is selected when compiling, when run from eclipse it gives the expected key and value, however when run from CF I get the caught errors.

My CF code is simply:

propTest = CreateObject("java","package.class"); testResults = propTest.main2();

Is there a special way to reference the .properties file so CF can access it, or do I need to include the file outside the .jar somewhere?

© Stack Overflow or respective owner

Related posts about java

Related posts about eclipse