我正在尝试使用geoip2为BungeeCord(Minecraft)编写插件。我试图包含依赖" com.maxmind.geoip2"以及我的jar文件中的BungeeCord API jar文件,因为我得到了java.lang.NoClassDefFoundError: com/maxmind/geoip2/exception/GeoIp2Exception
java.lang.NoClassDefFoundError: com/maxmind/geoip2/exception/GeoIp2Exception
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.getDeclaredConstructor(Class.java:2178)
at net.md_5.bungee.api.plugin.PluginManager.enablePlugin(PluginManager.java:305)
at net.md_5.bungee.api.plugin.PluginManager.loadPlugins(PluginManager.java:212)
at net.md_5.bungee.BungeeCord.start(BungeeCord.java:259)
at net.md_5.bungee.BungeeCordLauncher.main(BungeeCordLauncher.java:56)
at net.md_5.bungee.Bootstrap.main(Bootstrap.java:15)
Caused by: java.lang.ClassNotFoundException: com.maxmind.geoip2.exception.GeoIp2Exception
at net.md_5.bungee.api.plugin.PluginClassloader.loadClass0(PluginClassloader.java:53)
at net.md_5.bungee.api.plugin.PluginClassloader.loadClass(PluginClassloader.java:27)
at java.lang.Cl
我已经尝试了this,但它对我没用。
在研究更多时,我遇到了maven着色器,我现在在我的pom.xml中有这个:
<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>general</groupId>
<artifactId>CubenexBungee</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>CubenexBungee</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
<build>
<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>
<configuration>
<artifactSet>
<excludes>
<exclude>org:*</exclude>
</excludes>
<includes>
<include>com.maxmind.geoip2:geoip2</include>
<include>Referenced Libraries:BungeeCord.jar</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我的App.java是:
public class App extends Plugin implements Listener{
public static DatabaseReader database;
@Override
public void onEnable(){
getProxy().getPluginManager().registerListener(this, this);
try {
database = new DatabaseReader.Builder(new File(this.getDataFolder().getPath()+"//countrydatabase.csv")).build();
} catch (IOException e) {
e.printStackTrace();
}
}
@EventHandler
public void login(LoginEvent e){
CountryResponse response;
try {
response = database.country(e.getConnection().getAddress().getAddress());
System.out.println(e.getConnection().getName()+" comes from "+response.getCountry().getName());
} catch (IOException e1) {
e1.printStackTrace();
} catch (GeoIp2Exception e1) {
e1.printStackTrace();
}
}
}
我必须说,我只是发现了关于maven的事情并且并不是非常了解它并且没有找到我理解的任何教程。
答案 0 :(得分:1)
你想要做的是很多人称之为'胖罐'或'超级罐'的东西 您可以使用maven-shade-plugin创建它 以下是有关它的更多信息:http://www.mkyong.com/maven/create-a-fat-jar-file-maven-shade-plugin/