Содержит файл JAR и зависимость в экспортированном файле JAR с Maven
Я пытаюсь запрограммировать плагин для BungeeCord (Minecraft) с geoip2. Я пытаюсь содержать зависимость "com.maxmind.geoip2" и файл jar API BungeeCord в моем файле 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
Я пробовал это, но у меня не получилось.
В процессе исследования я наткнулся на шейдер 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 и не очень хорошо понимаю это, и не нашел никаких учебных пособий, которые я понимаю.
1 ответ
То, что вы пытаетесь сделать, это то, что многие люди называют "толстой банкой" или "убер-банкой"
Вы можете создать это с помощью maven-shade-plugin.
Вот больше информации об этом: http://www.mkyong.com/maven/create-a-fat-jar-file-maven-shade-plugin/