GWT 2.4:“发生内部编译器异常”在使用Hibernate进行Bean验证的项目中 [英] GWT 2.4: "An internal compiler exception occurred" in project that uses Hibernate for Bean Validation

查看:104
本文介绍了GWT 2.4:“发生内部编译器异常”在使用Hibernate进行Bean验证的项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我决定在我的GWT项目中使用JSR 303 Bean Validation后,大约5个小时,我得说我甚至不能表达(礼貌地)我对。


It's been about 5 hrs since I decided to use JSR 303 Bean Validation in my GWT project and I gotta say I can't even express (politely) how deeply unsatisfied I am with lame documentation on the subject on Google's website.

I really hope you guys can help me.

I followed this blog post to add client-side bean validation to my project. Unfortunately it worked only once and threw an exception in runtime saying that I need to add Hibernate Validation sources to class path. I fixed that and decided to remassage my dependencies a little too (biggest mistake of my life) but I couldn't make it work ever again.

I can't play with Validation sample from GWT SDK either because it's uncompilable because it has two implementations of class ServerValidator. Weird.

So to simplify my question I created dummy GWT application using project wizard of IntelliJ IDEA.

I added following elements to module xml:

<inherits name="org.hibernate.validator.HibernateValidator"/>
<replace-with class="com.mySampleApplication.client.ClientValidatorFactory">
    <when-type-is class="javax.validation.ValidatorFactory"/>
</replace-with>

Created ClientValidatorFactory:

package com.mySampleApplication.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.validation.client.AbstractGwtValidatorFactory;
import com.google.gwt.validation.client.GwtValidation;
import com.google.gwt.validation.client.impl.AbstractGwtValidator;

import javax.validation.Validator;
import javax.validation.groups.Default;

public class ClientValidatorFactory extends AbstractGwtValidatorFactory
{
    @GwtValidation(value = {Organization.class}, groups = {Default.class, ClientGroup.class})
    public interface GwtValidator extends Validator
    {
    }

    @Override
    public AbstractGwtValidator createValidator()
    {
        return GWT.create(GwtValidator.class);
    }
}

And in onModuleLoad() method I added this single line which causes compiler to blow up

Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

And finally I used following jars which I copied from Validation sample of GWT SDK.

hibernate-validator-4.1.0.Final-sources.jar
hibernate-validator-4.1.0.Final.jar
log4j-1.2.16.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
validation-api-1.0.0.GA-sources.jar
validation-api-1.0.0.GA.jar

But when I compile my project it gives following meaningless error:

In detailed GWT compiler log I see this:

Loaded 2315 units from persistent store.
   Found 2282 cached units.  Used 2282 / 2282 units from cache.
   Added 0 units to persistent cache.
   Validating newly compiled units
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/engine/ConstraintViolationImpl_CustomFieldSerializer.java'
         Line 33: No source code is available for type org.hibernate.validator.engine.ConstraintViolationImpl<T>; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/engine/ValidationSupport.java'
         Line 43: No source code is available for type org.hibernate.validator.engine.ConstraintViolationImpl<T>; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/constraints/impl/EmailValidator.java'
         Line 25: No source code is available for type org.hibernate.validator.constraints.Email; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/constraints/impl/ScriptAssertValidator.java'
         Line 26: No source code is available for type org.hibernate.validator.constraints.Email; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/constraints/impl/URLValidator.java'
         Line 26: No source code is available for type org.hibernate.validator.constraints.URL; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/engine/PathImpl.java'
         Line 72: No source code is available for type org.hibernate.validator.engine.NodeImpl; did you forget to inherit a required module?

Why can't it find classses? I have hibernate-validator-4.1.0.Final-sources.jar in my classpath.

Any thoughts ?

I uploaded my project here if you guys want to play with it.

解决方案

Case closed, guys. Error was caused by lack of hibernate validation sources in classpath because of bug in IntelliJ IDEA. Details are here.

这篇关于GWT 2.4:“发生内部编译器异常”在使用Hibernate进行Bean验证的项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆