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 jUnit error loading script class


    Kazpersky

    Recommended Posts

    So I've tried creating a script with maven and it seems to be having some issues with jUnit. Only in terminal though, the script runs.

    The project structure was auto generated with intelij, also added the jUnit dependancy just to be sure.

    Edit:

    Forgot to mention it only prints out that error message while refresing script manager. And it's the only script located there.

    Here is the error log: 

    23:56:33: [ERROR] Error loading script class: C:\Users\nosta\DreamBot\Scripts\original-script-name-uberjar.jar![org/codehaus/plexus/PlexusTestCase.class]:
    	java.lang.NoClassDefFoundError: junit/framework/TestCase
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClass(Unknown Source)
    	at java.security.SecureClassLoader.defineClass(Unknown Source)
    	at java.net.URLClassLoader.defineClass(Unknown Source)
    	at java.net.URLClassLoader.access$100(Unknown Source)
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at org.dreambot.1R.1(1R.java)
    	at org.dreambot.1R.3(1R.java)
    	at org.dreambot.1R.0a(1R.java)
    	at org.dreambot.1R.0b(1R.java)
    	at org.dreambot.1R.6(1R.java)
    	at org.dreambot.2v.lambda$refreshScripts$8(2v.java)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: junit.framework.TestCase
    	at java.net.URLClassLoader.findClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	... 18 more

     And here is how my pom.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <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.example</groupId>
        <artifactId>mavenScriptTemplate</artifactId>
        <version>1.0</version>
        <!-- dreambot cdn -->
        <repositories>
            <repository>
                <id>dreambot</id>
                <name>dreambot</name>
                <url>https://cdn.dreambot.org/maven/</url>
            </repository>
        </repositories>
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13.2</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.dreambot</groupId>
                <artifactId>client</artifactId>
                <version>3.0.0</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
            </dependency>
        </dependencies>
    
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
    
            <!-- dreambot properties -->
            <dreambot.path>${user.home}/DreamBot/</dreambot.path>
        </properties>
    
        <!-- build jar file with dependencies -->
        <packaging>jar</packaging>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.2.4</version>
                    <configuration>
                        <finalName>script-name-uberjar</finalName>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <artifactSet>
                            <excludes>
                                <exclude>junit:junit</exclude>
                            </excludes>
                        </artifactSet>
                        <shadedClassifierName>dep-included</shadedClassifierName>
                        <outputDirectory>${dreambot.path}/Scripts</outputDirectory>
                        <transformers>
    <!--                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">-->
    <!--                            <mainClass>mavenScriptTemplate</mainClass>-->
    <!--                        </transformer>-->
                        </transformers>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>module-info.class</exclude>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.maven.surefire</groupId>
                            <artifactId>surefire-junit47</artifactId>
                            <version>3.0.0-M5</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    
    </project>

     

    Link to comment
    Share on other sites

    • 2 weeks later...
    • 2 weeks later...

    I haven't tried to run your pom but you have a ClassDefNotFound so at run time of that refreshScript method the Class Loader can't find junit.framework.TestCase class. 

    I see you are excluding JUnit from your shaded JAR, you might try removing that. It's difficult to say what exactly is going on without knowing what refreshScript does though. 

    Link to comment
    Share on other sites

    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.