Compile Issue

Discussion in 'Spigot Plugin Development' started by Justin393, Sep 23, 2019.

  1. I recently ran into this error when building my plugin with Maven.

    Code (Text):
    [15:06:54] [Server thread/INFO]: justin_393 issued server command: /mcpe staff menu
    [15:06:54] [Server thread/WARN]: java.lang.reflect.InvocationTargetException
    [15:06:54] [Server thread/WARN]:     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [15:06:54] [Server thread/WARN]:     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [15:06:54] [Server thread/WARN]:     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [15:06:54] [Server thread/WARN]:     at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    [15:06:54] [Server thread/WARN]:     at jjbat_000.mondocommand.dynmaic.SubCommandFinder$1.handle(SubCommandFinder.java:67)
    [15:06:54] [Server thread/WARN]:     at jjbat_000.mondocommand.MondoCommand.handleRawCommand(MondoCommand.java:106)
    [15:06:54] [Server thread/WARN]:     at jjbat_000.mondocommand.MondoCommand.handle(MondoCommand.java:69)
    [15:06:54] [Server thread/WARN]:     at jjbat_000.mondocommand.MondoCommand.handleRawCommand(MondoCommand.java:106)
    [15:06:54] [Server thread/WARN]:     at jjbat_000.mondocommand.MondoCommand.onCommand(MondoCommand.java:59)
    [15:06:54] [Server thread/WARN]:     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45)
    [15:06:54] [Server thread/WARN]:     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159)
    [15:06:54] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:739)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.PlayerConnection.handleCommand(PlayerConnection.java:1800)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.PlayerConnection.a(PlayerConnection.java:1608)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:47)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:5)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:23)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.TickTask.run(SourceFile:18)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.MinecraftServer.aX(MinecraftServer.java:1013)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.MinecraftServer.executeNext(MinecraftServer.java:1006)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeAll(IAsyncTaskHandler.java:95)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:1135)
    [15:06:54] [Server thread/WARN]:     at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:919)
    [15:06:54] [Server thread/WARN]:     at java.base/java.lang.Thread.run(Thread.java:834)
    [15:06:54] [Server thread/WARN]: Caused by: java.lang.NoClassDefFoundError: jjbat_000/minecraftplanetearth/Util/Menus
    [15:06:54] [Server thread/WARN]:     at jjbat_000.minecraftplanetearth.commands.CommandStaff.menu(CommandStaff.java:49)
    [15:06:54] [Server thread/WARN]:     ... 27 more
    Did some research and found out that the error means the .class file is available at compile, but not at runtime. So I decompiled my plugin and opened up Menus.class and found this :

    Screenshot (23).png

    Obviously the class is not empty, and I have used this exact class multiple times, it's just now that this problem decided to show up. I'm building with "mvn clean install" and I'm using Maven 3.6.1

    Here is my pom.xml if that is useful at all:
    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>jjbat_000.minecraftplanetearth</groupId>
        <artifactId>MinecraftPlanetEarth</artifactId>
        <version>1.0</version>
        <packaging>jar</packaging>

        <name>MinecraftPlanetEarth</name>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
            <mainClass>jjbat_000.minecraftplanetearth.Core</mainClass>
            <author>Justin</author>
            <mavan.compiler.source>1.8</mavan.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>

        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <id>sk89q-repo</id>
                <url>http://maven.sk89q.com/repo/</url>
            </repository>
            <repository>
                <id>elmakers-repo</id>
                <url>http://maven.elmakers.com/repository/ </url>
            </repository>
            <repository>
                <id>placeholderapi</id>
                <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</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.12.2-R0.1-SNAPSHOT</version> -->
                <version>1.14.4-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.sk89q.worldguard</groupId>
                <artifactId>worldguard-bukkit</artifactId>
                <version>7.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.bukkit</groupId>
                <artifactId>bukkit</artifactId>
                <version>1.6.4-R2.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>de.slikey</groupId>
                <artifactId>EffectLib</artifactId>
                <version>1.4</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>net.raidstone</groupId>
                <artifactId>WorldGuardEvents</artifactId>
                <version>1</version>
                <scope>system</scope>
                <systemPath>C:\Users\Justin\Desktop\DebugServer\plugins\WorldGuardEvents.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.ksanur</groupId>
                <artifactId>MenuAPI</artifactId>
                <version>1</version>
                <scope>system</scope>
                <systemPath>C:\Users\Justin\Desktop\DebugServer\plugins\MenuAPI.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>spigot</groupId>
                <artifactId>server</artifactId>
                <version>1</version>
                <scope>system</scope>
                <systemPath>C:\Users\Justin\Desktop\DebugServer\PaperSpigot.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>towny</groupId>
                <artifactId>com.palmergames</artifactId>
                <version>1</version>
                <scope>system</scope>
                <systemPath>C:\Users\Justin\Desktop\TestServer\plugins\Towny.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>jjbat_000.eco</groupId>
                <artifactId>MinecraftPlanetEarthEconomy</artifactId>
                <version>1</version>
                <scope>system</scope>
                <systemPath>C:\Users\Justin\Desktop\DebugServer\plugins\Meco.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>me.clip</groupId>
                <artifactId>placeholderapi</artifactId>
                <version>2.9.2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.github.JavaFactoryDev</groupId>
                <artifactId>LightningStorage</artifactId>
                <version>2.3.8</version>
            </dependency>
        </dependencies>

        <build>
            <defaultGoal>clean package</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>jjbat_000.minecraftplanetearth</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>

    </project>
     
     
  2. // INTERNAL ERROR // in JD-GUI simply means that the decompiler can't read that class file. (Usually, that only means you're using an outdated version and you should update). If updating doesn't work, open the .jar with 7-Zip (or WinRAR) and open the .class with an editor.

    It's highly likely that your issue is not related to compiling. Check what line 49 in CommandStaff.java calls and check if it's available. Maybe you could also think about not shading your API into every plugin, but rather using it as a plugin so that you can call it from all your other plugins too.
     
  3. When I have a chance to get back to my computer in a few hours I’ll post some code. Until then, I’ll leave a few things I know for sure.
    I have used that exact method before, with 0 issues. The only thing I changed was running it async because it resolves multiple player heads (placing all online player heads into a GUI) and it was considerably laggy while doing so.

    And unless I completely mis-understand Maven I am not shading my API into my plugin. The only shading im doing is shading in the resource LightningStorage, which is exactly what the dev says to do.
     
  4. Here's the entire method involved with CommandStaff.java:49
    Code (Java):
    @Sub(rank = Rank.MOD, description = "Open Mod menu", allowConsole = false)
        public void menu(CallInfo call) {
            Player p = call.getPlayer();
                Menus.openOnlinePlayerList(p);    // <----- Line 49
        }
    Which calls this method in Menus.java

    Code (Java):

         
    public static void openOnlinePlayerList(Player p) {
            ChestMenu cm = new ChestMenu(54, ChatColor.DARK_GREEN + "Mod menu");
            if (core.getOnlinePlayers().isEmpty()) {
                p.sendMessage(ChatColor.RED + "No one is online!");
                return;
            }
            for (int i = 0; i < core.getOnlinePlayers().size(); i++) {
                String player = core.getOnlinePlayers().get(i).toString();
                EPlayer ePlayer = core.getEPlayer(Bukkit.getPlayer(player).getUniqueId());
                int j = i;
                new BukkitRunnable() {
                    @Override
                    public void run() {
                        TileEntitySkull.b(new GameProfile(null, player), gameProfile -> {
                            ItemStack skull = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
                            SkullMeta meta = (SkullMeta) skull.getItemMeta();
                            meta.setOwner(player);
                            meta.setDisplayName(player);
                            List<String> lore = new ArrayList<>();
                            lore.add("Click to manage");
                            meta.setLore(lore);
                            skull.setItemMeta(meta);
                            cm.setOption(j, skull);
                            return false;
                        }, false);
                    }
                }.runTaskAsynchronously(core);
            }
            cm.setClickHandler(new Menu.MenuClickEventHandler() {
                public void onMenuClick(Menu.MenuClickEvent event) {
                    if (event.getClicked() != null && event.getClickedName() != null) {
                        String name = ChatColor.stripColor(event.getClickedName());
                        if (core.getEPlayer(Bukkit.getPlayer(name).getUniqueId()).getRank().value >= Rank.MOD.value)
                            return;
                        new BukkitRunnable() {
                            @Override
                            public void run() {
                                openPlayerMenu(p, Bukkit.getPlayer(name));
                            }
                        }.runTaskLater(Core.getInstance(), 2L);
                        event.setWillClose(true);
                    } else
                        event.setWillClose(false);
                }
            });
            cm.open(p);
        }

        }
     
    #4 Justin393, Sep 24, 2019
    Last edited: Sep 24, 2019

  5. You need to set the scope to compile, i.e. <scope>compile</scope> for the dependency to be shaded. It seems like you omitted it for LightingStorage.

    On a side note, there's a couple of other issues with your pom.xml.
    • Your artifact id should be all lowercase with hyphens in place of spaces.
      (Maven's guide to naming conventions)
    • You don't need the <mainClass/> property since it's a spigot plugin/library.
    • You can also omit <java.version/>.
    • Not sure if the dependencies all have repositories, but you should avoid using a system path for dependencies when possible.
    • Why do you have a dependency on Spigot 1.14.4, Bukkit 1.6 and PaperSpigot which version is not even correct?
    • Generally, the default goal is "clean package install", not "clean package".
    • You don't need to declare the source and target for maven compiler again since you declared it as a property. You should remove either one. Even better if you use the new <maven.compiler.release/> instead.
     
  6. That actually fixed all the issues.

    Also, i tried building without <mainClass> and the plugin refused to load saying it couldn't find the main class. I re-added it and worked perfectly fine.