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