Results 1 to 2 of 2

Thread: Reading properties file

  1. #1
    Join Date
    Jan 2011
    Posts
    5

    Default Reading properties file

    In my java app there is a code which reads the properties file from src/main/resources folder.

    Code:
    @Component("mailerProperties")
    public class MailerProperties {
    
    	private static Properties properties;
    	
    	public MailerProperties() {
    		properties = new Properties();
    		InputStream inStream;
    		try {
    			inStream = (new ClassPathResource("mailer.properties")).getInputStream();			
    			properties.load(inStream);
    		} catch (IOException e) {			
    			e.printStackTrace();
    		}	
    	}
    	
    	public String getValue(String key) {
    		return properties.getProperty(key);
    	}
    
    	
    }
    Now I need to create a jar file and also remove the properties file from src/main/resources folder and place it outside the jar file(in the same location as jar file) so that data inside it can be changed easily in future.

    Question: Currently it uses ClassPathResource("mailer.properties") to read the prop file. What change I need to make to read it from outside the jar file

  2. #2
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    286

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •