My project team develops a browsergame with GWT with a Maven-structure:
- Parent
- Api
- Domain
- Service
- View
GWT is used mainly in the view (except for inheriting the other modules to the view) and we implemented the internationalization there. So far this configuration is running.
Now we wanted to also internationalize different error-messages which will be thrown to the user’s view, but coming from the Service-module.
Therefore it would be advantegeously to access the same property-files as the View-module. The problem is (obviously) that we cannot access the view from the service because of its order in the parent pom.
Would it be possible to outsource the internationalization-interface into the api so that we can access it from everywhere?
Thanks in advance.
Specialization:
Wether it’s not as easy as I might think or I did something wrong. I try to specialize my problem to check out the problem I have.
I have a Api.gwt.xml within the Api-module (de.ba.sy.api), referencing to my packages in there:
<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>
The interface ILanguage and also the properties lie within the language-package.
- de.ba.sy.api.language
- ILanguage.class
- ILanguage_de.properties
- ILanguage_en.properties
- ILanguage.properties
Within the View-module there’s lying the structure:
- de.ba.sy.view
- Application.gwt.xml (inheriting the Api-module)
- client
- Application.class
In Application.class I have now the code:
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);
}
}
So like I said if I keep the ILanguage and its properties within the View-module there’s no problem, but when I move it into the Api-module I get:
[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_
Thank you again. I just started with GWT, therefore I don’t know if this is trivial or not.
Since GWT 2.5, you can use
GWT.create()in a JVM (i.e. on the server), provided there’s a registered provider for the class passed as argument; and it comes with internationalization built-in, so you can use your interface andGWT.create()call on the server.To answer your question then: yes, you can move the interface and properties files to your Api module.
Note that you have to use the
com.google.gwt.core.shared.GWTclass, notcom.google.gwt.core.client.GWT.