Jersey - Maven - MessageBodyWriter 未找到媒体类型=应用程序/json

Sup*_*p89 3 json web-services jersey jersey-client jersey-2.0

目前我遇到的问题是 Netbeans 中的所有内容都可以正常工作,但是如果我使用命令“java -jar FILENAME PARAMETERS”启动 jar 文件,则会出现以下错误。

未找到 Media type=application/json、type =class java.util.ArrayList、genericType=java.util.List 的 MessageBodyWriter

我需要专家来解决这个问题:/。这很奇怪,因为当我在 Netbeans 中执行 jar 时它可以工作。

pom.xml

http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>at.schneider.development</groupId>
<artifactId>PhotoBoothImageService</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>PhotoBoothImageService</name>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>${jersey.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-grizzly2-http</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.9</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.coobird</groupId>
        <artifactId>thumbnailator</artifactId>
        <version>[0.4, 0.5)</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                      <manifest>
                            <mainClass>at.schneider.development.photoboothimageservice.Main</mainClass>
                      </manifest>
                    </archive>
            </configuration>
            <executions>
              <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
              </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<properties>
    <jersey.version>2.26-b02</jersey.version>
    <jdk.version>1.8</jdk.version>
</properties>
Run Code Online (Sandbox Code Playgroud)

功能:

@GET
@Path("/getimages")
@Produces(MediaType.APPLICATION_JSON)
public List<Image> getImages() {
    availableImages = getImageListFromDirectory(Paths.get(configuration.getProperties().get(BASE_DIR).toString()));
    return availableImages;
}
Run Code Online (Sandbox Code Playgroud)

谢谢指教!

此致

Het*_*ett 5

我找到了答案评论Supercop89

jersey-media-json-jackson 必须是第一个依赖项。