2

我在 github 上创建了一个简单的项目(参见那里的源代码)。

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

如果我用它创建一个 jarmvn package并运行它,我无法 curl 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 依赖项?

4

1 回答 1

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>
于 2012-12-13T13:10:25.743 回答