I wrote a small application. I put information about a specific database in the properties file.
db.url=jdbc:mysql://localhost:3306/librarydb db.user=root db.passwd=pas$w0rd
When I create an application to get the jar executable, the properties file is included internally. The whole purpose of putting this information in the properties file is to allow the user to modify them, but this makes it impossible.
How to include a properties file with a jar file in it? As if you are doing with the AppSettings file in .NET applications.
I am very new to Java, so I would appreciate it if you could break it down into several stages.
Thanks.
EDIT:
This is how I get 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; } }
Isuru
source share