Maven:" javax.json"并没有被包含在" uber" jar通过maven-compiler-plugin

时间:2014-04-26 04:14:44

标签: java maven

所以我在过去一个月左右一直在使用Maven将我需要的依赖项编译到我创建的特定jar中,有效地制作了一个“超级”jar。

这是我的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>

如您所见,我正在使用maven-compiler-plugin来“构建”该项目。它会将org.jsoupcom.github.axet编译成“uber”jar,没有任何问题,但由于某种原因,它不会添加javax.json

我已经确认它没有通过使用WinRAR查看jar内容来添加javax.json。运行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

如果我正在构建jar的IDE很重要,我正在使用最新版本的IntelliJ CE

任何见解都将受到赞赏。

1 个答案:

答案 0 :(得分:-1)

你只对json-api有依赖。它不包括你的异常抱怨的类Json.java。您还需要为json-api提供实现,例如:

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.0.4</version>
</dependency>

(来自https://jsonp.java.net/download.html

我想在打包之前你没有注意到这一点,因为你的IDE或其中的东西可能会为json-api提供无形的实现。