0

I am trying to load a .properties file(s) into my distributable jar file. This is what I did so far:

In my config.properties file, I defined this properties

jdbc.driverClassName = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://localhost:3306/testdb
jdbc.username = root
jdbc.password =

and on my class DBManager, I have this methods:

//Default Constructor
public DBManagerImpl(){
    JDBC_DRIVER = getResource().getProperty("jdbc.driverClassName","com.mysql.jdbc.Driver");
    try {
        Class.forName(JDBC_DRIVER);
    }...
}

//Getting properties file
private Properties getResource(){
    Properties prop = new Properties();
    InputStream input = null;
    try {
        input = getClass().getClassLoader().getResourceAsStream("config.properties");
        prop.load(input);
    } ...
    return prop;
}

public Connection getConnection() {
    Connection connection = null;
    try {
        DATABASE_URL = getResource().getProperty("jdbc.url", "jdbc:mysql://localhost:3306/defaultdb");
        username = getResource().getProperty("jdbc.username", "root");
        password = getResource().getProperty("jdbc.password", "");
        connection = DriverManager.getConnection(DATABASE_URL, username, password);
    } ...
    return connection;
}

Like wise, I also have another file, book.csv, which contains list of book to be loaded on my table.

My problem now is that upon upon generating a jar file, if I change my definitions on config.properties or modify my book.csv and run my distributable file it does not render changes.

Hope someone can point out solution.

Any help is very much appreciated

  • *"if I change my definitions on config.properties or modify my book.csv and run my distributable file it does not render changes."* DYM the Jar is being rebuilt? By "I" DYM you the developer or you the end user? – Andrew Thompson Mar 07 '18 at 21:22
  • It does not rebuilt. And yeah, I am referring to the end user. The purpose in creating the config is to dynamically change the database. I mean instead of localhost, the end user can change another database location. – Anirudh Lou Mar 08 '18 at 02:21

0 Answers0