I am in the process of working on a discord bot for a class, and I am having trouble with my token and github. I am trying to set it up so that the token is read from a config.properties file that can be updated with a bot token. However, my professor said that I should be setting it up so that I have a binary executable that can be downloaded as a release from the GitHub repo and users should simply provide their own config.properties file in the designated folder they are instructed. However, I don't understand/know how I can compile an executable Java program that is dependent on the value of the file read at runtime without recompiling after every time that the config.properties file is changed. Right now, I have the application set up as a JAR file, and I don't know how else to make the program downloadable to a user without sharing it as a JAR, but that means it needs to be recompiled after each change to the config.properties file. I'm at a loss and not sure I totally understand JAR files.
EDIT: Here's the code I am using to read in my config properties.
public class ReadConfig {
String token = "";
InputStream inputStream = null;
// won't take string with file
String file = "config.properties";
Properties prop = new Properties();
public String getToken() throws IOException{
try{
inputStream = getClass().getClassLoader().getResourceAsStream(file);
prop.load(inputStream);
token = prop.getProperty("token");
// System.out.println("Token: " + token);
} catch (Exception e){
System.out.println("Exception: " + e);
} finally {
inputStream.close();
}
return token;
}
}
My config.properties file is structured below:
# Config properties for the bot
token=TOKENHERE
I've been using the Gradle ShadowJar plugin in Intellij to create the executable JAR. I've tried moving the JAR to the same folder as the config.properties file, and updating the config.properties file between runs but if I update with an invalid token, it will still work until I completely rebuild and compile the JAR over again.