#External libraries

1 messages · Page 1 of 1 (latest)

woven karma
#

Hi guys,
I have a question about external libraries. After I made my own library for something simple just to find out how to work with it, I found ClassNotFoundException in console.

Where will plugin find classes of my library when the library .jar is only on my computer or how to properly make this libraries using maven?
I tried my best to find this at my own but i can't find solution, so i hope somebody has more practice than me 😂

unkempt bronze
#

You will need to load your library on the server so it knows what the classes are

thorn ferry
#

you have to shade it i guess

unkempt bronze
#

You can do this by either shading it or making the library in to it's own plugin

woven karma
thorn ferry
#

shading basically 'places' the library in your jar

#

you can use the maven shade plugin for that

#

sec

unkempt bronze
thorn ferry
#

example of my pom:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <relocations>
                        <relocation>
                            <pattern>co.aikar.commands</pattern>
                            <shadedPattern>me.fourteendoggo.xkingdoms.acf</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>co.aikar.locales</pattern>
                            <shadedPattern>me.fourteendoggo.xkingdoms.locales</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>com.zaxxer.hikari</pattern>
                            <shadedPattern>me.fourteendoggo.xkingdoms.hikari</shadedPattern>
                        </relocation>
                    </relocations>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>```
where `<relocation></relocation>` is a specific item that needs to be shaded
#

so basically <shadedPattern>your.package.name.relocationname</shadedPattern>

woven karma
#

Ok i see but what is going into <pattern></pattern>?

unkempt bronze
#

pattern is the package name

woven karma
#

So i made something like that:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <relocations>
                        <relocation>
                            <pattern>cz.darklabs.darklabslib</pattern>
                            <shadedPattern>sk.adr3ez_.antibuild</shadedPattern>
                        </relocation>
                    </relocations>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <outputFile>C:\pracovná plocha\FOLDERS\1st - Minecraft\testing1.18.2\DLL.jar</outputFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>```
But still **ClassNotFoundException**
thorn ferry
#

can we see your whole pom

woven karma
thorn ferry
#

did you press the maven reload button?

woven karma
#

yes 😄