I've written a small application. I've put the database specific information in a properties file.
db.url=jdbc:mysql://localhost:3306/librarydb
db.user=root
db.passwd=pas$w0rd
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.
How can I include a properties file with the jar file not in it? Kinda like you do with AppSettings file in .NET applications.
I'm very new to Java so I'd appreciate if you could break it down to a set of steps.
Thank you.
EDIT :
This is how I'm getting the values from the properties file in my program.
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;
}
}
App.config
file in .NET. When the executable is created, the file is bundled with it, right? Not inside it. – MondeFileInputStream
instead ofgetResourceAsStream
. – Canzonetproperties
file? And should I useFileInputStream
orgetResourceAsStream
? – Gonococcus