Test project to get used to Java Discord API lib
- Clone the repo to your machine
- Run Mavens
install
lifecycle - Go to Mavens
target/externalConfigs
folder and rename thedefault_discordSettings.properties
file. Remove the leadingdefault_
string. This will let the application read the file for gathering all necessary data for connecting to discord. - Copy the following files from mavens
target
folder to your desired application folder:
target
|
+-- HowTo_JavaDiscordAPI-<versionNumber>.jar
|
+-- lib/
|
+-- externalConfigs/
- Now go to your applications folder and type the following command, for running the
application
java -jar HowTo_JavaDiscordAPI-<versionNumber>.jar
Properties-Files placed inside the projects src/main/resources/externalConfigs
folder
will be moved to externalConfigs
subfolder of the installed JAR file as soon as mavens install
lifecycle is getting started. The copy-mechanism is defined in the pom.xml
file,
using mavens maven-resources-plugin. Those properties files will not be included inside the JAR output file
of your application if you're going to run mavens install
lifecycle. To exclude the folder from JAR
file, the maven-jar-plugin is used inside the pom.xml.
Keep in mind that you can place your discordSettings.properties
file with your discord
token into the project folder. This file is already git-ignored.
When you are going to use Mavens install
lifecycle, all project related dependencies are going to be copied to
the /lib
subfolder of the installed project by using maven-dependency-plugin inside the pom.xml
file.
Additionally, you have to point to the new lib folder inside the JAR's MANIFEST file.
This is set by using the classPath
value of Mavens maven-jar-plugin inside the pom.xml
file.
You can define the behaviour of the log4j-logger by changing the values inside the log4j.properties file. A short description can be found on the Oracle website here.
Here you have to put all the Discord related stuff into. The file is located at the externalConfigs
subfolder
of the installed application or at the project folder src/main/java/resources/externalConfigs
- settings.discord.token=
Put in the token for your discord-application (bot). Before this application can be run, you have to ensure that you have created a discord bot first. Here is a small HowTo on how to create your own discord bot for getting you started.
Discord API Wrapper for Java.
JDA only uses the logging API slf4j. You can select
whatever logger lib you want that is compatible with slf4j.
So both dependencies are necessary. I decided to use log4j. This is included in the reload4j lib.
Some links to video tutorials I used for tose examples in here