我的 jar 中缺少标准消息正文阅读器提供程序

发布于 2024-12-14 06:20:16 字数 788 浏览 1 评论 0原文

我现在肯定错过了两天的东西......

我有一个简单的 jar 应用程序,它使用球衣客户端 jar。 当我从 Eclipse 或 mvn exec 运行我的主类时,一切都很顺利。

当我构建 jar 然后使用 java -jar 运行它时,我得到:

com.sun.jersey.api.client.ClientHandlerException:未找到 Java 类 java.lang.String、Java 类型类 java.lang.String 和 MIME 媒体类型 application/json 的消息正文读取器

,即所有标准 Java 类型我客户的提供商列表中缺少正文阅读器提供商。

我在客户端的 pom.xml 依赖项中声明为:

  • jersey-client
  • jersey-core
  • jersey-json
  • jersey-server
  • jackson-mapper-asl
  • jackson-core-asl
  • jersey-multipart

使我的应用程序正常工作的唯一方法是在中声明 StringProvider 类我客户的配置...

config.getClasses().add(StringProvider.class);

但是这个提供者声明必须只对自定义 bean 是必要的?默认情况下可以访问标准 bean 提供程序吗?不是吗?

I must missing something for two days now...

I have a simple jar app which use a jersey client jar.
When I run my main class from Eclipse or from mvn exec everything goes fine.

When I build my jar then run it with a java -jar, I get :

com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class java.lang.String, and Java type class java.lang.String, and MIME media type application/json was not found

i.e. all standard Java types body readers providers are missing from my client's providers list.

I declare in the client's pom.xml dependencies to :

  • jersey-client
  • jersey-core
  • jersey-json
  • jersey-server
  • jackson-mapper-asl
  • jackson-core-asl
  • jersey-multipart

The only way for making my app working is to declare StringProvider class in my client's config...

config.getClasses().add(StringProvider.class);

But this provider decleration must only be necessary for custom beans? Standard bean providers are accessible by default? Aren't they?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的十字路口 2024-12-21 06:20:16

我在发布近一年后发现了这一点,但事实证明我的问题是由于使用阴影将所有内容合并到一个罐子中。添加更多变压器似乎已经解决了问题。我的阴影插件配置现在看起来像这样:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.0</version>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.sandwormz.jettycore.NotezWebsocketMain</mainClass>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/javax.ws.rs.ext.MessageBodyReader</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/javax.ws.rs.ext.MessageBodyWriter</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.sandwormz.jettycore.NotezWebsocketMain</mainClass>
                            </transformer>
                        </transformers>
                        <filters>
                            <filter>
                                This is required if we want anything build on top of this
                                to
                                compile without security errors.
                                <artifact>*</artifact>
                                <excludes>
                                    <exclude>**/*.MF</exclude>
                                    <exclude>**/*.SF</exclude>
                                    <exclude>**/*.DSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>

希望这对某人有帮助。

I'm finding this almost a year after it was posted, but turns out that my problem was due to merging everything into a single jar using shade. Adding a couple more transformers seems to have fixed things up. My shade plugin conf now looks like so:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.0</version>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.sandwormz.jettycore.NotezWebsocketMain</mainClass>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/javax.ws.rs.ext.MessageBodyReader</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/javax.ws.rs.ext.MessageBodyWriter</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.sandwormz.jettycore.NotezWebsocketMain</mainClass>
                            </transformer>
                        </transformers>
                        <filters>
                            <filter>
                                This is required if we want anything build on top of this
                                to
                                compile without security errors.
                                <artifact>*</artifact>
                                <excludes>
                                    <exclude>**/*.MF</exclude>
                                    <exclude>**/*.SF</exclude>
                                    <exclude>**/*.DSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Hope this helps someone.

昇り龍 2024-12-21 06:20:16

您是否将所有类捆绑在一个 jar 中(包括球衣模块中的类)?如果是这样,那么看起来您丢失了一些 META-INF 文件,或者您以一种模块中的同名文件覆盖了其他模块中的同名文件的方式合并了它。

Are you bundling all the classes in a single jar (including the classes from jersey modules)? If so, then this looks like you are missing some META-INF files or you merged it in such a way that one file of the same name in one module overwrote a file with the same name from some other module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文