Discord4j issue

Hey,
so recently I started programing a little plugin for me and my friends to play hardcore together. Now I had the great idea to implement a discord bot who sends the current IP of the server into a discord channel.

All good but if I try to start the server i get an error:

can anyone help me on this?

It seems like you aren’t shading in Discord4J. Are you using a build system like maven or gradle?

I tried to shade it and my .jar looks like that:

image

I really dont know how shading works. I invested 2 hours in fixing this now

Are you using maven/gradle? If so could you post what you have tried in your pom.xml or build.gradle/kts?

maven and here:

 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>HardCorePlugin</shadedClassifierName>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>at.noah.hardcoreplugin.Main</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Ok so I found a “fix” or rather nice tutorial on youtube

if you have this problem too try these steps:

go in your pom and add this in your

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>at.noah.hardcoreplugin.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Note: You have to specify the of your dependency you want to include. For me it was:

<dependency>
        <groupId>com.discord4j</groupId>
        <artifactId>discord4j-core</artifactId>
        <version>3.1.7</version>
        <scope>compile</scope>
    </dependency>

After that you can go in your project dir with explorer and open up cmd. Make sure you are in the right folder.

Now just type in “mvn clean install” and it should create a “target” dir with the executable jar. Now search the one which includes “jar-with-dependencies” and put that one in your plugins folder.

I did not test that with the maven tools in intellij but that should work too.

Note: if you cant run mvn you have to include maven in your environment variables: https://stackoverflow.com/questions/45119595/how-to-add-maven-to-the-path-variable