title: Include A Properties File With A Jar File
body: <p>I've written a small application. I've put the database specific information in a properties file. </p>
  
  <pre><code>db.url=jdbc:mysql://localhost:3306/librarydb
  db.user=root
  db.passwd=pas$w0rd
  </code></pre>
  
  <p>When I build the application to get the executable jar file, the properties file gets included inside. The whole purpose of putting those information in a properties file is to allow the user to change those but this is making it impossible.</p>
  
  <p>How can I include a properties file with the jar file not in it? Kinda like you do with AppSettings file in .NET applications.</p>
  
  <p>I'm very new to Java so I'd appreciate if you could break it down to a set of steps. </p>
  
  <p>Thank you. </p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>This is how I'm getting the values from the properties file in my program.</p>
  
  <pre><code>public class DatabaseHandler {
  
      public static Connection connectToDb() {
          Connection con = null;
          Properties props = new Properties();
          InputStream in = null;
  
          try {
              in = DatabaseHandler.class.getResourceAsStream("database.properties");
              props.load(in);
              in.close();
  
              String url = props.getProperty("db.url");
              String user = props.getProperty("db.user");
              String password = props.getProperty("db.passwd");
  
              con = DriverManager.getConnection(url, user, password);
          } catch (Exception ex) {        
              Logger.getLogger(DatabaseHandler.class.getName()).log(Level.SEVERE, null, ex); 
          }
              return con;
      }
  
  }
  </code></pre>