Java 使用maven在导出的jar文件中包含jar文件和依赖项
我正在尝试用geoip2为BungeeCord Minecraft编程一个插件。我试图在jar文件中包含依赖项com.maxmind.geoip2和BungeeCord API jar文件,因为我得到了一个java.lang.NoClassDefFoundError:com/maxmind/geoip2/exception/GeoIp2Exception 我试过了,但不管用 在研究更多内容时,我遇到了maven shader,目前我的pom.xml中有:Java 使用maven在导出的jar文件中包含jar文件和依赖项,java,maven,bukkit,bungeecord,geoip2,Java,Maven,Bukkit,Bungeecord,Geoip2,我正在尝试用geoip2为BungeeCord Minecraft编程一个插件。我试图在jar文件中包含依赖项com.maxmind.geoip2和BungeeCord API jar文件,因为我得到了一个java.lang.NoClassDefFoundError:com/maxmind/geoip2/exception/GeoIp2Exception 我试过了,但不管用 在研究更多内容时,我遇到了maven shader,目前我的pom.xml中有: <project xmlns="h
<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>
我必须说,我只是刚刚了解了maven,并没有很好地理解它,也没有找到任何我理解的教程。你试图制作的是很多人称之为“胖罐子”或“优步罐子”的东西 您可以使用maven shade插件来创建它。
以下是关于它的更多信息:为什么Maven组装插件方法不适合您?我不知道。。。。。我所知道的是,我仍然发现了NoClassDefFound错误。请尝试查看maven shade/Shadowjar因为您是maven的新手,您是否更新了pom.xml?当向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>
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();
}
}
}