Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Maven + Dreambot = Jar with dependencies


    yeeter

    Recommended Posts

    Posted

    Saw some people having issues with Dreambot and libs.   Thought I would yeet this in the snippets real quick to save someone else the trouble of writing their own.  This is a premade pom file for Maven.  If you are unfamiliar with Maven it is a build automation tool created by Apache.   It is great for managing dependencies for building self contained private scripts so no more lib/dependency fuckery.

    For starters in the properties change the dreambot.path to wherever your DreamBot folder is located.  On Windows this is C:/Users/yeeter01/Dreambot
     

    <properties>
    	<dreambot.path>C:/Users/yeeter01/DreamBot</dreambot.path>
    </properties>

    To add dependencies its as simple as going out to a maven repository like https://mvnrepository.com/ and finding the dependencies you want to use.   I will use google protobuf and simple json for this example

     

    <dependencies>
    		<dependency>
    			<groupId>com.google.protobuf</groupId>
    			<artifactId>protobuf-java</artifactId>
    			<version>3.11.0</version>
    		</dependency>
    
    		<dependency>
    			<groupId>com.google.protobuf</groupId>
    			<artifactId>protobuf-java-util</artifactId>
    			<version>3.11.0</version>
    		</dependency>
    
    		<dependency>
    			<groupId>com.googlecode.json-simple</groupId>
    			<artifactId>json-simple</artifactId>
    			<version>1.1.1</version>
    		</dependency>
    
    		<dependency>
    			<groupId>dreambot</groupId>
    			<artifactId>client</artifactId>
    			<version>1.0.0</version>
    			<scope>system</scope>
    			<systemPath>${dreambot.path}/BotData/client.jar</systemPath>
    		</dependency>
    	</dependencies>

     

    Now for the part that was a pain in my ass initially.. the build.  We will use the maven-shade plugin in order to create a shaded jar.  This is just a fancy uber jar.

    Jar packaging information -> https://dzone.com/articles/the-skinny-on-fat-thin-hollow-and-uber
    Apache Shade plugin information -> https://maven.apache.org/plugins/maven-shade-plugin/

     

    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-shade-plugin</artifactId>
    				<version>3.2.1</version>
    				<configuration>
    					<shadedArtifactAttached>true</shadedArtifactAttached>
    					<shadedClassifierName>dep-included</shadedClassifierName>
    					<outputDirectory>${dreambot.path}/Scripts</outputDirectory>
    				</configuration>
    				<executions>
    					<execution>
    						<phase>package</phase>
    						<goals>
    							<goal>shade</goal>
    						</goals>
    					</execution>
    				</executions>
    			</plugin>
    		</plugins>
    	</build>

     

    Smash that maven build button and BOOM!  Out comes 2 jar files. 'original-yeetware-0.0.1-SNAPSHOT' and 'yeetware-0.0.1-SNAPSHOT'.  The file with the original prefix is the normal jar generated by maven.  The other will be your shaded jar which can be thrown into the scripts folder ready to rock.   You  can get really fancy with this and auto output the script into there, delete the original, upload to a fileserver etc but this was just a barebones example.

    FULL FILE

     

    <project xmlns="http://maven.apache.org/POM/4.0.0"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>org.db.yeet</groupId>
    	<artifactId>yeetBarrowsPort</artifactId>
    	<version>0.1</version>
    	<name>plz work</name>
    
    	<properties>
    		<dreambot.folder.path>C:/Users/yeeter01/DreamBot</dreambot.folder.path>
    	</properties>
    
    	<dependencies>
    		<dependency>
    			<groupId>com.google.protobuf</groupId>
    			<artifactId>protobuf-java</artifactId>
    			<version>3.11.0</version>
    		</dependency>
    
    		<dependency>
    			<groupId>com.google.protobuf</groupId>
    			<artifactId>protobuf-java-util</artifactId>
    			<version>3.11.0</version>
    		</dependency>
    
    		<dependency>
    			<groupId>com.googlecode.json-simple</groupId>
    			<artifactId>json-simple</artifactId>
    			<version>1.1.1</version>
    		</dependency>
    
    		<dependency>
    			<groupId>dreambot</groupId>
    			<artifactId>client</artifactId>
    			<version>1.0.0</version>
    			<scope>system</scope>
    			<systemPath>${dreambot.path}/BotData/client.jar</systemPath>
    		</dependency>
    
    	</dependencies>
    
    
    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-shade-plugin</artifactId>
    				<version>3.2.1</version>
    				<configuration>
    					<shadedArtifactAttached>true</shadedArtifactAttached>
    					<shadedClassifierName>dep-included</shadedClassifierName>
    					<outputDirectory>${dreambot.path}/Scripts</outputDirectory>
    				</configuration>
    				<executions>
    					<execution>
    						<phase>package</phase>
    						<goals>
    							<goal>shade</goal>
    						</goals>
    					</execution>
    				</executions>
    			</plugin>
    		</plugins>
    	</build>
    
    </project>

     

    *Disclaimer*
    I am no maven expert so probably better ways to do it.

    Posted

    Thanks for sharing. Pretty sweet, and I like that you can rename dependencies internally.

    • 6 months later...
    Posted

    this man is a genius, tysm bro repped !

    • 3 weeks later...
    Posted

    TYVM. Very, very helpful.

    • 11 months later...
    Posted

    Thanks Yeeter! btw, is it possible to do this but implementing scripts in Kotlin? I don't personally like writing in Java 😕

    Posted
    3 hours ago, botmaker_01 said:

    Thanks Yeeter! btw, is it possible to do this but implementing scripts in Kotlin? I don't personally like writing in Java 😕


    It's the same setup, and you can make scripts with Kotlin, although I don't think we have any guides specific to that (?).

    Please note that while local scripts are fine with Kotlin, they can't be added to our public SDN (if that was your plan at all).

    • 2 weeks later...
    Posted
    On 10/1/2021 at 2:59 AM, Pandemic said:


    It's the same setup, and you can make scripts with Kotlin, although I don't think we have any guides specific to that (?).

    Please note that while local scripts are fine with Kotlin, they can't be added to our public SDN (if that was your plan at all).

    If I show the code and the pom.xml file for the dependencies n stuff it still can't be added? (not sure if I'm planning to add anything it anyways). 
    For me it just seems that Kotlin is the way to go as it's basically more functionalities for less code. 

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.