What is this problem with maven?

Discussion in 'Spigot Plugin Development' started by Kyllian, Apr 6, 2017.

  1. Hey

    This is my error:

    Code (Text):
    [18:42:48 ERROR]: Could not pass event AsyncPlayerChatEvent to Shortr v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at net.minecraft.server.v1_11_R1.PlayerConnection.chat(PlayerConnection.java:1266) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1204) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat$1.run(PacketPlayInChat.java:39) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_121]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_121]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.NoClassDefFoundError: net/swisstech/bitly/builder/v3/ShortenRequest
            at me.kyllian.shortr.listeners.OnPlayerChatEvent.onPlayerChatEvent(OnPlayerChatEvent.java:40) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            ... 11 more
    Caused by: java.lang.ClassNotFoundException: net.swisstech.bitly.builder.v3.ShortenRequest
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_121]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_121]
            at me.kyllian.shortr.listeners.OnPlayerChatEvent.onPlayerChatEvent(OnPlayerChatEvent.java:40) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            ... 11 more
    My pom:

    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>me.kyllian</groupId>
        <artifactId>Shortr</artifactId>
        <version>1.00</version>
        <name>Shortr</name>
        <description>The solution to long links</description>
        <build>
            <finalName>Shortr</finalName>
            <directory>D:\Work Folder\Java\MavenProjects</directory>
            <defaultGoal>install</defaultGoal>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <!-- Keeping filtering at true here reduces plugin.yml redundancy! -->
                    <filtering>true</filtering>
                    <includes>
                        <include>plugin.yml</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <!-- Keep filtering at false for other resources to prevent bad magic -->
                    <filtering>false</filtering>
                    <excludes>
                        <exclude>**/*.java</exclude>
                        <exclude>plugin.yml</exclude>
                    </excludes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</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>2.4.3</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <artifactSet>
                                    <includes>
                                        <include>net.swisstech:*:*</include>
                                    </includes>
                                    <includes>
                                        <include>org.slf4j:*:*</include>
                                    </includes>
                                </artifactSet>
                                <minimizeJar>true</minimizeJar>
                            </configuration>
                        </execution>
                     
                    </executions>
                </plugin>
            </plugins>
        </build>
        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
                <id>bintray-stackmagic-maven</id>
                <name>bintray</name>
                <url>http://dl.bintray.com/stackmagic/maven</url>
            </repository>
        </repositories>
        <dependencies>
            <!--Spigot API -->
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.8-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <!-- Bitly -->
            <dependency>
                <groupId>net.swisstech</groupId>
                <artifactId>bitly-api-client</artifactId>
                <version>0.8.0</version>
                <type>jar</type>
            </dependency>
            <!-- idk -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.22</version>
            </dependency>
        </dependencies>
    </project>
     
    and then I have my error line(s):

    Code (Text):
                ShortenRequest code = new ShortenRequest("MYTOKENISCENSORED");
                code.setLongUrl(s);
                Bukkit.broadcastMessage(code.getEndpoint());
    API:

    https://github.com/stackmagic/bitly...wisstech/bitly/builder/v3/ShortenRequest.java
     
  2. Try changing this
    Code (Text):
    <include>net.swisstech:*:*</include>
    to this
    Code (Text):
    <include>net.swisstech:bitly-api-client</include>
     
  3. Okay that makes my pom.xml this:;

    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>me.kyllian</groupId>
        <artifactId>Shortr</artifactId>
        <version>1.00</version>
        <name>Shortr</name>
        <description>The solution to long links</description>
        <build>
            <finalName>Shortr</finalName>
            <directory>D:\Work Folder\Java\MavenProjects</directory>
            <defaultGoal>install</defaultGoal>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <!-- Keeping filtering at true here reduces plugin.yml redundancy! -->
                    <filtering>true</filtering>
                    <includes>
                        <include>plugin.yml</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <!-- Keep filtering at false for other resources to prevent bad magic -->
                    <filtering>false</filtering>
                    <excludes>
                        <exclude>**/*.java</exclude>
                        <exclude>plugin.yml</exclude>
                    </excludes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</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>2.4.3</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <artifactSet>
                                    <includes>
                                        <include>net.swisstech:bitly-api-client</include>
                                    </includes>
                                    <includes>
                                        <include>org.slf4j:*:*</include>
                                    </includes>
                                </artifactSet>
                                <minimizeJar>true</minimizeJar>
                            </configuration>
                        </execution>
                       
                    </executions>
                </plugin>
            </plugins>
        </build>
        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
                <id>bintray-stackmagic-maven</id>
                <name>bintray</name>
                <url>http://dl.bintray.com/stackmagic/maven</url>
            </repository>
        </repositories>
        <dependencies>
            <!--Spigot API -->
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.8-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <!-- Bitly -->
            <dependency>
                <groupId>net.swisstech</groupId>
                <artifactId>bitly-api-client</artifactId>
                <version>0.8.0</version>
                <type>jar</type>
            </dependency>
            <!-- idk -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.22</version>
            </dependency>
        </dependencies>
    </project>
     
    But with still this error:

    Code (Text):
    [19:17:10 ERROR]: Could not pass event AsyncPlayerChatEvent to Shortr v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at net.minecraft.server.v1_11_R1.PlayerConnection.chat(PlayerConnection.java:1266) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1204) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat$1.run(PacketPlayInChat.java:39) [spigot.jar:git-Spigot-7d78b81-613be0d]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_121]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_121]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.NoClassDefFoundError: net/swisstech/bitly/builder/v3/ShortenRequest
            at me.kyllian.shortr.listeners.OnPlayerChatEvent.onPlayerChatEvent(OnPlayerChatEvent.java:40) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            ... 11 more
    Caused by: java.lang.ClassNotFoundException: net.swisstech.bitly.builder.v3.ShortenRequest
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_121]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_121]
            at me.kyllian.shortr.listeners.OnPlayerChatEvent.onPlayerChatEvent(OnPlayerChatEvent.java:40) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-7d78b81-613be0d]
            ... 11 more
     
  4. Weird. I always do it like this. Note: You can place all your includes into one <includes> tag:
    Code (Text):
    <includes>
        <include>net.swisstech:bitly-api-client</include>
        <include>org.slf4j:slf4j-log4j12</include>
    </includes>
     
  5. I putted them in to one tag now but still the same problem
     
  6. You could check this two things:
    1. In your Maven log should appear messages like this:
      Code (Text):
      [INFO] --- maven-shade-plugin:3.0.0:shade (default) @ yourplugin ---
      [INFO] Including dependency:dependency:jar:1.0 in the shaded jar.
      (only example values). Make sure that your dependency is there too.
    2. Open your Plugin.jar with 7-Zip or similar and check if your dependencies have been shaded.
     
  7. Code (Text):
    [INFO] --- maven-shade-plugin:2.4.3:shade (default) @ Shortr ---
    [INFO] Including net.swisstech:bitly-api-client:jar:0.8.0 in the shaded jar.
    [INFO] Excluding com.google.code.gson:gson:jar:2.3.1 from the shaded jar.
    [INFO] Excluding joda-time:joda-time:jar:2.8.1 from the shaded jar.
    [INFO] Excluding org.slf4j:slf4j-api:jar:1.7.12 from the shaded jar.
    [INFO] Including org.slf4j:slf4j-log4j12:jar:1.7.22 in the shaded jar.
    [INFO] Excluding log4j:log4j:jar:1.2.17 from the shaded jar.
     
  8. Code (Text):
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.4.3</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <minimizeJar>true</minimizeJar>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    No need for includes or excludes. Just enable the shade plugin and let it do its thing.

    Control which dependencies get included using the scope for each dependency.

    Code (Text):
        <dependencies>
            <!--Spigot API -->
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.8-R0.1-SNAPSHOT</version>
                <scope>provided</scope><!-- does NOT include in shaded jar -->
            </dependency>
            <!-- Bitly -->
            <dependency>
                <groupId>net.swisstech</groupId>
                <artifactId>bitly-api-client</artifactId>
                <version>0.8.0</version>
                <scope>compile</scope><!-- includes in shaded jar -->
            </dependency>
            <!-- idk -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.22</version>
                <scope>compile</scope><!-- includes in shaded jar -->
            </dependency>
        </dependencies>
     
    • Winner Winner x 1
  9. You guy, you are my hero <3
     

Share This Page