【问题标题】:Deploying an ear containing an Application Client on Glassfish 3.1.2 throws exceptions在 Glassfish 3.1.2 上部署包含应用程序客户端的 ear 会引发异常
【发布时间】:2012-12-09 04:22:38
【问题描述】:

我问这个问题只是为了让我自己回答,因为这两天让我发疯,没有人应该像我一样受苦。

当我展开耳朵时,我会遇到这样的异常:


Exception while invoking class org.glassfish.appclient.server.core.AppClientServerApplication start method
org.jvnet.hk2.component.ComponentException: injection failed on org.glassfish.appclient.server.core.jws.JavaWebStartInfo.dch with class org.glassfish.appclient.server.core.jws.DeveloperContentHandler
    at org.jvnet.hk2.component.InjectionManager.error_injectionException(InjectionManager.java:284)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:161)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:93)
.
.
Caused by: org.jvnet.hk2.component.ComponentException: Failed to create class org.glassfish.appclient.server.core.jws.DeveloperContentHandler
.
.
Caused by: java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
.
.

或者有时像这样:


Exception while loading the app : injection failed on org.glassfish.appclient.server.core.jws.JavaWebStartInfo.dch with class org.glassfish.appclient.server.core.jws.DeveloperContentHandler
org.jvnet.hk2.component.ComponentException: Failed to create class org.glassfish.appclient.server.core.jws.DeveloperContentHandler
    at com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:71)
    at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:80)
.
.
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.appclient.server.core.jws.DeveloperContentHandler

这个错误非常令人费解,因为在一台机器上运行良好的 ear 文件可能无法在另一台机器上部署,并且服务器可能会被该问题“感染”并拒绝部署以前运行良好的 ear。清除缓存和生成的文件不会让它消失。

【问题讨论】:

  • 我相信当我们不在耳朵中包含依赖罐,而是在 glassfish ([...]/ext 或类似的)。但这当然可能只是统计数据和安慰剂。

标签: java glassfish glassfish-3 ear application-client


【解决方案1】:

经过数小时的摆弄,我想我已经找到了答案——问题是由于 ear lib 文件夹中包含一个 xerxes-impl jar 文件引起的。我怀疑通过一些类加载怪异它正在替换服务器自己的 xml 解析器。这解释了奇怪的感染问题,因为类路径问题在服务器重新启动之前不会消失。任何 xml 解析器都可能会出现问题,但我没有检查过。

要解决此问题,请关闭 glassfish,确保您部署的 ear 中没有 xerces,然后重新启动 glassfish 并部署新的 clean ear 文件。它应该工作。它对我有用。如果做不到这一点,我认为你唯一的办法就是献血。

【讨论】:

    【解决方案2】:

    JDK 定义了 javax.xml.parsers.DocumentBuilderFactory 接口并提供了默认实现。服务提供者可以通过设置系统属性“javax.xml.parsers.DocumentBuilderFactory”来替换实现类。当您部署 xerces 时,它使用此属性来提供它自己的实现。

    来自 javax.xml.parsers.DocumentBuilderFactory 的片段:

       public static DocumentBuilderFactory newInstance() {
        try {
            return (DocumentBuilderFactory) FactoryFinder.find(
                /* The default property name according to the JAXP spec */
                "javax.xml.parsers.DocumentBuilderFactory",
                /* The fallback implementation class name */
                "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
        } catch (FactoryFinder.ConfigurationError e) {
            throw new FactoryConfigurationError(e.getException(),
                                                e.getMessage());
        }
    
    }
    

    所有这些也适用于 javax.xml.parsers.SAXParserFactory。

    选择解析器实现

    如果没有指定其他工厂类,则使用默认的 SAXParserFactory 类。要使用来自不同制造商的解析器,您可以更改指向它的环境 > 变量的值。您可以从命令行执行此操作:

    java -Djavax.xml.parsers.SAXParserFactory=yourFactoryHere [...]

    您指定的工厂名称必须是完全限定的类名(所有包前缀>包括在内)。有关详细信息,请参阅 >SAXParserFactory 类的 newInstance() 方法中的文档。

    http://docs.oracle.com/javase/tutorial/jaxp/sax/validation.html

    【讨论】:

      猜你喜欢
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 2014-09-20
      • 1970-01-01
      相关资源
      最近更新 更多