I'm currently developing a Velocity Minecraft plugin, and I'm encountering a ClassNotFoundException for FileUtils from org.apache.commons.io.FileUtils, even though I have added the library to my project's dependencies in the pom.xml file.
All compiles fine, but when I run the plugin on my velocity proxy server and execute the command, I get the ClassNotFoundException.
I'm using Velocity version 3.2.0-SNAPSHOT and Java 17 for my project. The dependency that causes the issue is org.apache.commons.io.FileUtils from commons-io version 2.13.0.
My Pom:
<?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>pvpstartplugin</groupId>
<artifactId>PvpStart</artifactId>
<version>0.1.0</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>
17
</java.version>
</properties>
<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>
</plugins>
</build>
<repositories>
<repository>
<id>maven-central</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
This is were I use FileUtils:
package pvpstartplugin.command;
import com.velocitypowered.api.command.SimpleCommand;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class PvP implements SimpleCommand {
@Override
public void execute(Invocation invocation) {
File sourceWorldDir = new File("/server/mc/castleGame/castleWorlds/Riveredgecastle/world");
File targetWorldDir = new File("/server/mc/castleGame/pvpServer/world");
try {
copyWorldContents(sourceWorldDir, targetWorldDir);
ProcessBuilder processBuilder = new ProcessBuilder("./start.sh");
processBuilder.directory(new File("/server/mc/castleGame/pvpServer"));
processBuilder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
private void copyWorldContents(File source, File target) throws IOException {
FileUtils.cleanDirectory(target);
FileUtils.copyDirectory(source, target);
}
}
I also tried version 2.11.0 of the library, but it did not work.
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<scope>compile</scope>
</dependency>
I have confirmed that the commons-io-2.13.0.jar is present in my ~/.m2/repository/org/apache/commons/commons-io/2.13.0/ directory.
Any help is appreciated