Skip to content

Use Apache Maven With DreamBot Scripting

What Is Maven?

Maven is a build automation tool developed by the Apache Software Foundation. It can be used to manage project dependencies, and build Java projects consistently in the same manner.

Why Use Maven?

Maven makes dependency management a breeze by automatically pulling in required dependencies for a project. In our case using Maven will allow us to skip the step of adding the DreamBot API to our project each time. This also allows us to import other 3rd party libraries that may be of use such as JavaCord, MQ frameworks, SQL adapters, and more.

Maven can also package the included dependencies with the jar file its self. This is referred to as an Uber or Fat jar. This means you will no longer have to place libs needed for scripts under /Libs/. This makes sharing a script is as simple as sending the .jar file.

Maven Properties

To start we well set our compiler target/sources to Java version 1.8. This will compile our scripts with the specified version of Java for compatibility.

By default DreamBot is placed in the user's home directory. We can access this path via ${user.home}. We can create a reference to the folder to help save us from typing it each time.

        <!-- java properties -->

        <!-- dreambot properties -->

Adding The DreamBot Dependency

In order to access the client we must add the DreamBot Content Deliver Network (CDN) repository. This allows us to pull the client from the CDN for use in our projects.

From there we can add then add the client dependency.

    <!-- dreambot cdn -->

    <!-- dependencies -->

Adding Other Dependencies

Adding other dependencies such as SQL connectors or MQ frameworks is as simple as copy and pasting the dependency into the dependencies group.

    <!-- dependencies -->

        <!-- mysql connector -->

        <!-- rabbit mq client -->

Build Plugin For Uber/Fat/Shaded Jars

Now that we have all of our dependencies added to our project we need to actually build our project. While using Maven we can avoid keeping copies of our dependencies on hand and just add them to the .jar file when we build it. There are a couple ways to do this but I prefer the shade plugin provided by Apache.

When the build is executed it will automatically dump the script in your /Scripts/ folder inside of DreamBot (yay for task automation!).

    <!-- build jar file with dependencies -->

Executing The Build

Depending on your IDE you can execute the build inside the IDE or via the command line buy just running a mvn install. Then all of the above will happen automatically for you!