Grizzy / Jersey:POJO映射不适用于Maven one-jar

时间:2012-12-12 14:55:45

标签: java maven jersey grizzly

我创建了一个简单的project on github(参见那些来源)。

如果我在Eclipse中将项目作为Maven项目导入并运行它,我可以卷曲XML / JSON资源。

如果我使用mvn package创建一个jar并运行jar,我就无法卷曲XML / JSON资源。我收到以下错误:

Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class de.dennis_boldt.resources.User, and Java type class de.dennis_boldt.resources.User, and MIME media type application/xml was not found

Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class de.dennis_boldt.resources.User, and Java type class de.dennis_boldt.resources.User, and MIME media type application/json was not found

我错过了什么吗?也许是Maven的依赖?

1 个答案:

答案 0 :(得分:0)

解决方案是使用maven-shade-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <manifestEntries>
                            <Main-Class>package.Main</Main-Class>
                            <Build-Number>1</Build-Number>
                        </manifestEntries>
                    </transformer>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                </transformers>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
        </execution>
    </executions>
</plugin>