我的项目团队使用具有 Maven 结构的 GWT 开发浏览器游戏:
- 家长
- api
- 领域
- 服务
- 看法
GWT 主要用在视图中(除了将其他模块继承到视图中),我们在那里实现了国际化。到目前为止,此配置正在运行。
现在我们还想国际化不同的错误消息,这些错误消息将被抛出到用户的视图中,但来自服务模块。因此,访问与视图模块相同的属性文件将是有利的。问题是(显然)我们无法从服务访问视图,因为它在父 pom.xml 中的顺序。
是否可以将国际化接口外包到 api 中,以便我们可以从任何地方访问它?
提前致谢。
专业化:
不管是不是我想的那么容易,还是我做错了什么。我尝试专门解决我的问题以检查我遇到的问题。
我在 Api 模块(de.ba.sy.api)中有一个 Api.gwt.xml,引用了我的包:
<module>
<!-- <inherits name="de.ba.sy.api.manager.IUserManager" /> -->
<inherits name="com.google.gwt.user.User" />
<!-- Hier können weitere packages eingefügt werden -->
<source path="dao" />
<source path="encoder" />
<source path="entity" />
<source path="exceptions" />
<source path="language" />
<source path="mail" />
<source path="manager" />
<source path="user" />
<source path="validator" />
</module>
接口 ILanguage 以及属性位于语言包中。
- de.ba.sy.api.language
- 语言类
- ILanguage_de.properties
- ILanguage_en.properties
- ILanguage.properties
在 View-module 中有结构:
- de.ba.sy.view
- Application.gwt.xml(继承 Api 模块)
- 客户
- 应用程序类
在 Application.class 我现在有代码:
package view.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import de.ba.sy.api.language.ILanguage;
/**
* @author stubbe
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Application implements EntryPoint {
/**
* This is the entry point method.
*/
public void onModuleLoad() {
/* Internationalisierung */
final ILanguage languages = GWT.create(ILanguage.class);
LoginPageForm login = new LoginPageForm(languages);
RootPanel.get().add(login);
}
}
所以就像我说的,如果我将 ILanguage 及其属性保留在 View-module 中就没有问题,但是当我将它移到 Api-module 中时,我得到:
[INFO] --- gwt-maven-plugin:2.5.0-rc1:compile (default-cli) @ View ---
[INFO] auto discovered modules [view.Application]
[INFO] Compiling module view.Application
[INFO] Validating units:
[INFO] Ignored 5 units with compilation errors in first pass.
[INFO] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[INFO] Computing all possible rebind results for 'de.ba.sy.api.language.ILanguage'
[INFO] Rebinding de.ba.sy.api.language.ILanguage
[INFO] Invoking generator com.google.gwt.i18n.rebind.LocalizableGenerator
[INFO] Processing interface de.ba.sy.api.language.ILanguage
[INFO] Generating method body for email()
[INFO] [ERROR] No resource found for key 'email'
[INFO] com.google.gwt.i18n.rebind.AbstractResource$MissingResourceException: No resource found for key 'email'
[INFO] at com.google.gwt.i18n.rebind.MessagesMethodCreator.createMethodFor(MessagesMethodCreator.java:1086)
[INFO] at com.google.gwt.i18n.rebind.AbstractLocalizableImplCreator.delegateToCreator(AbstractLocalizableImplCreator.java:501)
[INFO] at com.google.gwt.i18n.rebind.MessagesImplCreator.emitMethodBody(MessagesImplCreator.java:92)
[INFO] at com.google.gwt.user.rebind.AbstractGeneratorClassCreator.genMethod(AbstractGeneratorClassCreator.java:277)
[INFO] at com.google.gwt.user.rebind.AbstractGeneratorClassCreator.emitMethods(AbstractGeneratorClassCreator.java:239)
[INFO] at com.google.gwt.user.rebind.AbstractGeneratorClassCreator.emitClass(AbstractGeneratorClassCreator.java:118)
[INFO] at com.google.gwt.i18n.rebind.AbstractLocalizableImplCreator.generateConstantOrMessageClass(AbstractLocalizableImplCreator.java:225)
[INFO] at com.google.gwt.i18n.rebind.LocalizableGenerator.generate(LocalizableGenerator.java:151)
[INFO] at com.google.gwt.i18n.rebind.LocalizableGenerator.generate(LocalizableGenerator.java:124)
[INFO] at com.google.gwt.core.ext.IncrementalGenerator.generateNonIncrementally(IncrementalGenerator.java:40)
[INFO] at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:657)
[INFO] at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
[INFO] at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:79)
[INFO] at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:276)
[INFO] at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:265)
[INFO] at com.google.gwt.dev.DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(DistillerRebindPermutationOracle.java:91)
[INFO] at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.handleGwtCreate(UnifyAst.java:355)
[INFO] at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.handleMagicMethodCall(UnifyAst.java:433)
[INFO] at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.endVisit(UnifyAst.java:237)
[INFO] at com.google.gwt.dev.jjs.ast.JMethodCall.traverse(JMethodCall.java:243)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265)
[INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:116)
[INFO] at com.google.gwt.dev.jjs.ast.JCastOperation.traverse(JCastOperation.java:65)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265)
[INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:116)
[INFO] at com.google.gwt.dev.jjs.ast.JCastOperation.traverse(JCastOperation.java:65)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265)
[INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:116)
[INFO] at com.google.gwt.dev.jjs.ast.JDeclarationStatement.traverse(JDeclarationStatement.java:48)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor$ListContextImmutable.traverse(JModVisitor.java:170)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.acceptWithInsertRemoveImmutable(JModVisitor.java:336)
[INFO] at com.google.gwt.dev.jjs.ast.JBlock.traverse(JBlock.java:83)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
[INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:137)
[INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:133)
[INFO] at com.google.gwt.dev.jjs.ast.JMethodBody.traverse(JMethodBody.java:82)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265)
[INFO] at com.google.gwt.dev.jjs.ast.JMethod.visitChildren(JMethod.java:426)
[INFO] at com.google.gwt.dev.jjs.ast.JMethod.traverse(JMethod.java:395)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
[INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265)
[INFO] at com.google.gwt.dev.jjs.impl.UnifyAst.mainLoop(UnifyAst.java:902)
[INFO] at com.google.gwt.dev.jjs.impl.UnifyAst.exec(UnifyAst.java:627)
[INFO] at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:604)
[INFO] at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:33)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:278)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:229)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:141)
[INFO] at com.google.gwt.dev.Compiler.run(Compiler.java:232)
[INFO] at com.google.gwt.dev.Compiler.run(Compiler.java:198)
[INFO] at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
[INFO] at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
[INFO] at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
[INFO] at com.google.gwt.dev.Compiler.main(Compiler.java:177)
[INFO] [WARN] Searched the following resources:
[INFO] [ERROR] Errors in 'view/client/Application.java'
[INFO] [ERROR] Line 23: Failed to resolve 'de.ba.sy.api.language.ILanguage' via deferred binding
[INFO] [WARN] For the following type(s), generated source was never committed (did you forget to call commit()?)
[INFO] [WARN] de.ba.sy.api.language.ILanguage_
再次感谢你。我刚开始使用 GWT,因此我不知道这是否微不足道。