Grizzly and Jersey standalone jar(灰熊和泽西独立罐)
问题描述
我正在尝试使用 Maven 阴影插件将 Grizzly 与 Jersey 打包为单个 jar.但我总是收到消息 No container provider supports the type class org.glassfish.grizzly.http.server.HttpHandler
I am trying to package Grizzly with Jersey as a single jar using Maven shade plugin. But I always get the message No container provider supports the type class org.glassfish.grizzly.http.server.HttpHandler
代码在 Eclipse 中运行良好,但在打包的 jar 中却不行:
The code works fine in Eclipse, but not in a packaged jar:
public class Main {
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost/").port(9998).build();
}
public static final URI BASE_URI = getBaseURI();
protected static HttpServer startServer() throws IOException {
System.out.println("Starting grizzly...");
ResourceConfig rc = new PackagesResourceConfig("share.test");
rc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
}
public static void main(String[] args) throws IOException {
HttpServer httpServer = startServer();
System.in.read();
httpServer.stop();
}
}
这里是完整的例外
$ java -jar target/webServiceTest-0.0.1-SNAPSHOT.jar
Starting grizzly...
Mar 20, 2012 12:48:53 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
share.test
Mar 20, 2012 12:48:54 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class share.test.NonJAXBBeanResource
class share.test.Hello
Mar 20, 2012 12:48:54 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Exception in thread "main" java.lang.IllegalArgumentException: No container provider supports the type class org.glassfish.grizzly.http.server.HttpHandler
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:196)
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:134)
at com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.createHttpServer(GrizzlyServerFactory.java:242)
at share.test.Main.startServer(Main.java:27)
at share.test.Main.main(Main.java:31)
我正在使用maven构建jar包
I am building the jar package using maven with
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>share.test.Main</Main-Class>
<Build-Number>1</Build-Number>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我是否需要更改阴影插件以包含其他内容?
Do I need to change the shade plugin to include anything else?
推荐答案
这个错误看起来像是插件没有正确合并来自不同 jar 的 META-INF/services 记录 - 如果 META 中有多个同名文件 -几个jar的INF/services目录,需要合并,不能一个一个替换.检查是否是这种情况.
The error looks like the plugin is not merging the META-INF/services records from different jars correctly - if there are multiple files with the same name in META-INF/services directory of several jars, they need to be merged, not replaced one by the other. Check if that is the case.
这篇关于灰熊和泽西独立罐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:灰熊和泽西独立罐
基础教程推荐
- 降序排序:Java Map 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01