Solved Eclipse ANT Builder help

Discussion in 'Spigot Plugin Development' started by Justin393, May 20, 2020.

  1. I'm having issues with using the ANT builder in Eclipse.

    In my pom.xml I am shading in an external plugin, but when Eclipse builds the plugin to run the test server inside of Eclipse it is not shading in the plugin, so I am getting a NoClassDefFound

    Here is the error:
    java.lang.NoClassDefFoundError: de/leonhard/storage/Yaml
    at justindevb.rustmc.Utils.FileUtil.createYaml(FileUtil.java:50) ~[?:?]
    at justindevb.rustmc.Utils.Settings.<init>(Settings.java:22) ~[?:?]
    at justindevb.rustmc.Core.initObjects(Core.java:94) ~[?:?]
    at justindevb.rustmc.Core.onEnable(Core.java:35) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:464) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:378) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:457) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:274) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_212]
    Caused by: java.lang.ClassNotFoundException: de.leonhard.storage.Yaml
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_212]
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:167) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:96) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_212]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_212]
    ... 13 more

    FileUtil:50
    Code (Java):
    Yaml yaml = new Yaml(name, core.getDataFolder().toString());
    My Builder.xml:

    Code (Text):
    <?xml version="1.0" ?>
    <!-- Configuration of the Ant build system to generate a Jar file -->
    <project name="RustMC" default="CreateJar">
      <target name="CreateJar" description="Create Jar file">
            <jar jarfile="./server/plugins/Plugin.jar" basedir="./target/classes/" includes="**/*" />
      </target>
    </project>
    Running the server locally in Eclipse works, I was doing it to test changes, it only recently broke once I needed to shade in the external library. If I decompile the plugin after Eclipse builds it, the library is not shaded in.
     
  2. Forgot to post my pom.xml :
    Code (Text):
    <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></groupId>
        <artifactId>RustMC</artifactId>
        <version>1.0</version>
        <packaging>jar</packaging>

        <name>RustMC</name>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <mainClass>rustmc.Core</mainClass>
            <author>Justin</author>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.source>1.8</maven.compiler.source>
        </properties>
        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <id>jitpack.io</id>
                <url>https://jitpack.io</url>
            </repository>
        </repositories>

        <dependencies>
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.15.2-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.github.JavaFactoryDev</groupId>
                <artifactId>LightningStorage</artifactId>
                <version>3.0.0</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>

        <build>
            <defaultGoal>clean package install</defaultGoal>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</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>3.1.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <relocations>
                            <relocation>
                                <pattern>de.leonhard</pattern>
                                <shadedPattern>rustmc</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </project>
    If no one has ideas on how to make it work, I might just end up removing it as a dependency and manually putting the classes into my project
     
    #2 Justin393, May 21, 2020
    Last edited: Aug 31, 2020
  3. Are you building using maven?
     
  4. I’m running the server inside of Eclispe, so I hit the run button. Up until I started using the shaded library it would work, but now it throws a NoClassDefFound and when I decompile the built plugin it’s not shaded.

    when I build it outside of eclipse with maven using “mvn clean install” it only packages the resources. I’ve been busy and haven’t had a chance to debug that yet.
     
  5. Finally had time to work on it again, I can now build it with “mvn clean install” on the command line and it works perfectly on a local server outside of eclipse. When I try launching it in eclipse I still get the NoClassDefFound, so it’s still not shading. And I have no idea how to get eclispe to shade a library in when running a builder
     
  6. Got it to work. Have to run a Maven build configuration within eclipse in order to do the shading. Changed the outputFile of the maven-shade-plugin configuration so the shaded jar is output into the eclipse server folder. After maven builds I just run the server like normal.