Skip to content

2) Eclipse Setup

Florian Spieß edited this page Feb 3, 2019 · 25 revisions

How to start developing with Eclipse

Download

To start developing with Eclipse, follow one of the guides below:

Help rewrite this page, send a direct message to Minn#6688 for further information


Jar Setup

  1. Download the latest (Binary) version of JDA (with Dependencies):
  1. Create a new Java Project
  2. Fill out the bot name, and set it to Java 8 (if available).

Java 8

  1. Right click the project, go to Properties
  2. Click on Java Build Path, then click on Libraries, then on Add External JARs...

Add JDA

  1. Add your downloaded JDA-withDependencies-x.x.x_xxx.jar and expand its properties
  • If you don't want Javadoc and source annotations, skip to 11 (not recommended).

Added And Expanded

  1. Click on Source Attachment, then on Edit..., then mark External Locations and click on External File

External File

  1. Here, add your JDA-x.x.x_xxx-sources.jar and click on OK
  2. Next, click on Javadoc Location, then on Edit..., then mark Javadoc in archive and click on Browse

Javadoc

  1. Here, add your JDA-x.x.x_xxx-javadoc.jar and click on OK

You Are Done! You can start by taking a look at the examples Here or Reading the docs Here.


Gradle Setup

  1. If you have Eclipse IDE for Java Developers installed, skip to 2., otherwise you need to install the Buildship Gradle Integration plugin first:
  • Open up Eclipse and go to the Marketplace (located under the Help tab)
  • Search for "gradle" and install Buildship Gradle Integration (Plugin-Page)
  • After the plugin is installed, relaunch Eclipse
  1. Right click within Package/Project Explorer and select New > Other...
  2. In the Gradle folder, select Gradle Project

Gradle Project

  1. Type a name for your Project and click on Finish. Your setup should look like this at this point:

Folder Structure

  1. Delete the classes within src/main/java and src/test/java
  2. Open up and edit the file build.gradle
  3. Replace its content with the following code:
plugins {
  id 'java'
  id 'application'
  id 'com.github.johnrengelman.shadow' version '1.2.4'
}

mainClassName = 'com.example.jda.Bot'

version '1.0'

sourceCompatibility = 1.8

repositories {
  jcenter()
  // Required for OkHTTP 3.13.0-SNAPSHOT
  maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

dependencies {
  compile 'net.dv8tion:JDA:X.X.X_XXX'
}

compileJava.options.encoding = 'UTF-8'
  1. Adjust the version of JDA you want to use (see dependencies-section of file) and fill in your Main-Class as soon as you have one (the one containing your public static void main(String[] args) method)
  2. Save the file and do the following: Right click your project > Gradle > Refresh All
  3. Once all of the dependencies have been downloaded, create your desired packages/classes in src/main/java and start coding!
  4. To build your project you can run gradlew shadowJar in a terminal of your project root and it will produce a jar filled with your compiled code and JDA included in a single jar file!

Maven Setup

Prerequisites: Maven-Plugin and local Maven installation

  1. Create a new Maven project. (File -> New -> Other -> Maven -> Maven Project)
  2. Now let's start configuring it, first off, open up your pom.xml and add the following lines right after </description>
<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>
  • This will make your project support UTF-8 characters (So you can have it on Japanese servers for example) and also force Java 8, which is needed.
  1. Now let's add JDA's repository so we can fetch the jar (Place this after </properties>)
<repositories>
  <repository>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
    <id>jcenter</id>
    <name>jcenter-bintray</name>
    <url>http://jcenter.bintray.com</url>
  </repository>
</repositories>
  1. Now, add the dependency, make sure you change X.X.X_XXX to the latest version number (Check out at https://ci.dv8tion.net/job/JDA/)
<dependencies>
  <dependency>
    <groupId>net.dv8tion</groupId>
    <artifactId>JDA</artifactId>
    <version>X.X.X_XXX</version>
    <type>jar</type>
    <scope>compile</scope>
  </dependency>
</dependencies>
  1. Now you need to set up the (build) maven-shade and maven-compile plugins, add the following lines right after </dependencies>
  • NOTE: The following changes will force the compiler to use Java 8 (JDA needs it), so make sure you have it installed.
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.5.1</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>2.4.3</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <artifactSet>
              <excludes>
                <exclude>example</exclude> <!-- You may add jars to exclude from shading -->
              </excludes>
            </artifactSet>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
  1. You are done! Now you can head to the Javadocs or see examples at the Examples page.