GWT 2 CssResource如何

Sha*_*hid 16 gwt

我有一个GWT 1.7应用程序,我想将它升级到GWT 2里程碑2.该应用程序使用2个大的外部CSS文件.在GWT 1.7中我有一个公共文件夹,并将CSS文件放在文件夹中,我的应用程序已编译并正常工作.现在对于GWT 2,我创建了一个ResourceBundle类,并将所有图像精灵和CSS放置如下:

public interface ResourceBundle extends ClientBundle {

 public static final ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);

 @Source("com/web/tech/public/stylesheet1.css")
 public Css stylesheet1();

 @Source("com/web/tech/public/stylesheet2.css")
 public Css stylesheet2();

 @Source("com/docobo/keswick/keswickweb/public/images/organisnew.gif")
 public ImageResource add_org();

.....
}
Run Code Online (Sandbox Code Playgroud)

Css类是一个扩展CssResource的空类:

public interface Css extends CssResource{

}
Run Code Online (Sandbox Code Playgroud)

然后在我的onModuleLoad()中使用:

StyleInjector.inject(ResourceBundle.INSTANCE.stylesheet1().getText());
StyleInjector.inject(ResourceBundle.INSTANCE.stylesheet2().getText());
Run Code Online (Sandbox Code Playgroud)

当我编译时,我收到以下错误:

     Rebinding com.docobo.keswick.keswickweb.client.ClientResources.ResourceBundle
            Invoking <generate-with class='com.google.gwt.resources.rebind.context.InlineClientBundleGenerator'/>
               Creating assignment for gxt_gray()
                  Replacing CSS class names
                     [ERROR] The following unobfuscated classes were present in a strict CssResource:
                        [ERROR] x-tab-scroller-left
                        [ERROR] x-tab-strip-disabled
                        [ERROR] ......loads of other styles

Fix by adding String accessor method(s) to the CssResource interface for obfuscated classes, or using an @external declaration for unobfuscated classes.
Run Code Online (Sandbox Code Playgroud)

按照上面的说明,当我在CSS文件中使用@external上面的所有样式类时,我得到以下错误:

 [ERROR] Generator 'com.google.gwt.resources.rebind.context.InlineClientBundleGenerator' threw threw an exception while rebinding 'com.docobo.keswick.keswickweb.client.ClientResources.ResourceBundle'
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
 at java.lang.String.substring(Unknown Source)
 at com.google.gwt.resources.css.GenerateCssAst$GenerationHandler.ignorableAtRule(GenerateCssAst.java:236)
 at org.w3c.flute.parser.Parser.atRuleDeclaration(Parser.java:1178)
 at org.w3c.flute.parser.Parser.ignoreStatement(Parser.java:622)
 at org.w3c.flute.parser.Parser.parserUnit(Parser.java:452)
 at org.w3c.flute.parser.Parser.parseStyleSheet(Parser.java:107)
 at org.w3c.flute.parser.Parser.parseStyleSheet(Parser.java:119)
 at com.google.gwt.resources.css.GenerateCssAst.exec(GenerateCssAst.java:663)
 at com.google.gwt.resources.rg.CssResourceGenerator.prepare(CssResourceGenerator.java:506)
 at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.initAndPrepare(AbstractClientBundleGenerator.java:531)
 at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.initAndPrepare(AbstractClientBundleGenerator.java:502)
 at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.generate(AbstractClientBundleGenerator.java:179)
 at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:49)
 at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRebindOracle.java:108)
 at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:54)
 at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:154)
 at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:143)
 at com.google.gwt.dev.Precompile$DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(Precompile.java:315)
 at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:107)
 at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.process(AbstractCompiler.java:161)
 at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
 at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:84)
 at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:196)
 at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.access$300(AbstractCompiler.java:70)
 at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:481)
 at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:113)
 at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:49)
 at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:415)
 at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:32)
 at com.google.gwt.dev.Precompile.precompile(Precompile.java:507)
 at com.google.gwt.dev.Precompile.precompile(Precompile.java:408)
 at com.google.gwt.dev.Compiler.run(Compiler.java:194)
 at com.google.gwt.dev.Compiler$1.run(Compiler.java:145)
 at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:89)
 at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:83)
 at com.google.gwt.dev.Compiler.main(Compiler.java:152)  
Run Code Online (Sandbox Code Playgroud)

小智 15

试试吧@NotStrict.例:

@NotStrict
@Source("com/web/tech/public/stylesheet1.css")
public Css stylesheet1();
Run Code Online (Sandbox Code Playgroud)


Sha*_*hid 7

得到了解决.正如Thomas @ Google Groups所指出的那样 - > @external不能被置于"风格之上"

http://code.google.com/p/google-web-toolkit/wiki/CssResource#External ...

来自此链接的示例,css将如下所示:

@external .legacySelectorA, .legacySelectorB;
.obfuscated .legacySelectorA { .... }
.obfuscated .legacySelectorB { .... }

/* @external also accepts tail-globs */
@external .myProject-*;
.myProject-text {}
.myProject-foo {}
Run Code Online (Sandbox Code Playgroud)