So I've been using Maven for the past month or so to compile dependencies that I need into the specific jar that I've created, effectively making an "uber" jar.
Here's my pom.xml
:
<?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>net.gamersbug</groupId>
<artifactId>GamersBug</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>GamersBug</name>
<url>http:/gamersbug.net/</url>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
<repository>
<id>confuser-repo</id>
<url>http://ci.frostcast.net/plugin/repository/everything</url>
</repository>
<repository>
<id>tagapi-repo</id>
<url>http://repo.kitteh.org/content/repositories/public/</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>me.confuser</groupId>
<artifactId>BarAPI</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.kitteh</groupId>
<artifactId>tagapi</artifactId>
<version>3.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.axet</groupId>
<artifactId>wget</artifactId>
<version>1.2.9</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/src/main/java/</sourceDirectory>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
As you can see, I am using maven-compiler-plugin
to "build" the project. It compiles both org.jsoup
and com.github.axet
into the "uber" jar with no problem, but for some reason it won't add javax.json
.
I've confirmed that it doesn't add javax.json
by viewing the jar contents with WinRAR. I also get the following error while running the jar.
Caused by: java.lang.NoClassDefFoundError: javax/json/Json
at net.gamersbug.main.commands.RegisterCommand.onCommand(RegisterCommand.java:73) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Spigot.jar:git-Spigot-1386]
... 13 more
Caused by: java.lang.ClassNotFoundException: javax.json.Json
If the IDE that I'm building jar with matters, I'm using the latest version of IntelliJ CE
.
Any insight would be appreciated.
You only have a dependency on json-api. It does not include the class Json.java that your exception is complaining about. You need to provide also an implementation for the json-api, for example:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
(from https://jsonp.java.net/download.html )
I guess prior to packaging you do not notice this because maybe your IDE or something in it is providing an implementation for json-api invisibly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.