gwt-maven-plugin在GWT maven反应堆构建中的maven模块中找不到源

时间:2015-02-22 13:08:13

标签: java maven gwt

我的目标是为模块化的RequestFactory项目创建maven reactor构建。我在GWT Code Server not finding a module in a newly generated project using a maven archetype

中使用了Thomas Broyer的maven原型

由于他的努力,它立即开箱即用,没有任何问题。它创建了三个模块(名称以client,server,shared结尾)。

有什么问题是三个项目的java源代码都在同一个包中。在项目启动并运行之后,我尝试做的一件事就是重构三个maven模块的包以实际以各自的名称结束。这适用于除客户端项目之外的所有项目,因为GWT编译器(gwt-maven-plugin)在构建客户端软件包时似乎不会在客户端项目自己的包之外查找源代码。

因此,如果共享项目拥有自己的包不是客户端的子包,这将导致GWT无法解析共享中的所有源。

我的问题是,我是否遗漏了一些明显的东西,或者我是否正在尝试做一些不推荐的事情?任何指针都将非常感激。

我一直在玩GWT和maven一段时间了,但我仍然不是专家所以请耐心等待我:-)。以下是我详细介绍的内容:

使用Thomas Broyer的原型创建项目(我第一次选择“N”以便能够第二次输入与“App”不同的模块名称):

mvn archetype:generate \
   -DarchetypeCatalog=https://oss.sonatype.org/content/repositories/snapshots/ \
   -DarchetypeGroupId=net.ltgt.gwt.archetypes \
   -DarchetypeArtifactId=modular-requestfactory \
   -DarchetypeVersion=1.0-SNAPSHOT

Define value for property 'groupId': : com.example
Define value for property 'artifactId': : my-modular-app
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  com.example: : com.example.my.modular.app
Define value for property 'module':  App: : MyModularApp
Define value for property 'module-short-name':  ${module.toLowerCase()}: :
Confirm properties configuration:
groupId: com.example
artifactId: my-modular-app
version: 1.0-SNAPSHOT
package: com.example.my.modular.app
module: MyModularApp
module-short-name: ${module.toLowerCase()}
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: modular-requestfactory:1.0-SNAPSHOT
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.example
[INFO] Parameter: artifactId, Value: my-modular-app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.example.my.modular.app
[INFO] Parameter: packageInPathFormat, Value: com/example/my/modular/app
[INFO] Parameter: package, Value: com.example.my.modular.app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: module, Value: MyModularApp
[INFO] Parameter: groupId, Value: com.example
Feb 22, 2015 12:51:56 PM org.apache.velocity.runtime.log.JdkLogChute log
INFO: FileResourceLoader : adding path '.'
[INFO] Parameter: module-short-name, Value: mymodularapp
[INFO] Parameter: artifactId, Value: my-modular-app
[INFO] Parent element not overwritten in /private/tmp/mvn/my-modular-app/my-modular-app-client/pom.xml
[INFO] Parent element not overwritten in /private/tmp/mvn/my-modular-app/my-modular-app-shared/pom.xml
[INFO] Parent element not overwritten in /private/tmp/mvn/my-modular-app/my-modular-app-server/pom.xml
[INFO] project created from Archetype in dir: /private/tmp/mvn/my-modular-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:35 min
[INFO] Finished at: 2015-02-22T12:51:56+01:00
[INFO] Final Memory: 16M/216M
[INFO] ------------------------------------------------------------------------

执行mvn clean install -Dgwt.draftCompile。工作就像一个魅力。

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] my-modular-app
[INFO] my-modular-app-shared
[INFO] my-modular-app-client
[INFO] my-modular-app-server
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-modular-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-modular-app ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-modular-app ---
[INFO] Installing /private/tmp/mvn/my-modular-app/pom.xml to /Users/nick/.m2/repository/com/example/my-modular-app/1.0-SNAPSHOT/my-modular-app-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-modular-app-shared 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-modular-app-shared ---
[INFO] Deleting /private/tmp/mvn/my-modular-app/my-modular-app-shared/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-modular-app-shared ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-shared/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ my-modular-app-shared ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-modular-app-shared ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-shared/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ my-modular-app-shared ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ my-modular-app-shared ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ my-modular-app-shared ---
[INFO] Building jar: /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/my-modular-app-shared-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ my-modular-app-shared ---
[INFO] Building jar: /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/my-modular-app-shared-1.0-SNAPSHOT-sources.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-modular-app-shared ---
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/my-modular-app-shared-1.0-SNAPSHOT.jar to /Users/nick/.m2/repository/com/example/my-modular-app-shared/1.0-SNAPSHOT/my-modular-app-shared-1.0-SNAPSHOT.jar
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-shared/pom.xml to /Users/nick/.m2/repository/com/example/my-modular-app-shared/1.0-SNAPSHOT/my-modular-app-shared-1.0-SNAPSHOT.pom
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/my-modular-app-shared-1.0-SNAPSHOT-sources.jar to /Users/nick/.m2/repository/com/example/my-modular-app-shared/1.0-SNAPSHOT/my-modular-app-shared-1.0-SNAPSHOT-sources.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-modular-app-client 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-modular-app-client ---
[INFO] Deleting /private/tmp/mvn/my-modular-app/my-modular-app-client/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-modular-app-client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-client/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ my-modular-app-client ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /private/tmp/mvn/my-modular-app/my-modular-app-client/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-modular-app-client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-client/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ my-modular-app-client ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ my-modular-app-client ---
[INFO] No tests to run.
[INFO]
[INFO] --- gwt-maven-plugin:2.7.0:compile (gwt-compile) @ my-modular-app-client ---
[INFO] Compiling module com.example.my.modular.app.MyModularApp
[INFO]    Compiling 3 permutations
[INFO]       Compiling permutation 0...
[INFO]       Process output
[INFO]          Compiling
[INFO]             Compiling permutation 1...
[INFO]       Process output
[INFO]          Compiling
[INFO]             Compiling permutation 2...
[INFO]    Compile of permutations succeeded
[INFO]    Compilation succeeded -- 8.061s
[INFO] Linking into /private/tmp/mvn/my-modular-app/my-modular-app-client/target/my-modular-app-client-1.0-SNAPSHOT/mymodularapp
[INFO]    Link succeeded
[INFO]    Linking succeeded -- 0.331s
[INFO]
[INFO] --- maven-war-plugin:2.5:war (default-war) @ my-modular-app-client ---
[INFO] Packaging webapp
[INFO] Assembling webapp [my-modular-app-client] in [/private/tmp/mvn/my-modular-app/my-modular-app-client/target/my-modular-app-client-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/private/tmp/mvn/my-modular-app/my-modular-app-client/src/main/webapp]
[INFO] Webapp assembled in [29 msecs]
[INFO] Building war: /private/tmp/mvn/my-modular-app/my-modular-app-client/target/my-modular-app-client-1.0-SNAPSHOT.war
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-modular-app-client ---
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-client/target/my-modular-app-client-1.0-SNAPSHOT.war to /Users/nick/.m2/repository/com/example/my-modular-app-client/1.0-SNAPSHOT/my-modular-app-client-1.0-SNAPSHOT.war
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-client/pom.xml to /Users/nick/.m2/repository/com/example/my-modular-app-client/1.0-SNAPSHOT/my-modular-app-client-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-modular-app-server 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-modular-app-server ---
[INFO] Deleting /private/tmp/mvn/my-modular-app/my-modular-app-server/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-modular-app-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-server/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ my-modular-app-server ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /private/tmp/mvn/my-modular-app/my-modular-app-server/target/classes
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:exec (requestfactory-validation-tool) @ my-modular-app-server ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-modular-app-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-server/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ my-modular-app-server ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ my-modular-app-server ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.5:war (default-war) @ my-modular-app-server ---
[INFO] Packaging webapp
[INFO] Assembling webapp [my-modular-app-server] in [/private/tmp/mvn/my-modular-app/my-modular-app-server/target/my-modular-app-server-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/private/tmp/mvn/my-modular-app/my-modular-app-server/src/main/webapp]
[INFO] Processing overlay [ id com.example:my-modular-app-client]
[INFO] Webapp assembled in [50 msecs]
[INFO] Building war: /private/tmp/mvn/my-modular-app/my-modular-app-server/target/my-modular-app-server-1.0-SNAPSHOT.war
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-modular-app-server ---
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-server/target/my-modular-app-server-1.0-SNAPSHOT.war to /Users/nick/.m2/repository/com/example/my-modular-app-server/1.0-SNAPSHOT/my-modular-app-server-1.0-SNAPSHOT.war
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-server/pom.xml to /Users/nick/.m2/repository/com/example/my-modular-app-server/1.0-SNAPSHOT/my-modular-app-server-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] my-modular-app ..................................... SUCCESS [  0.185 s]
[INFO] my-modular-app-shared .............................. SUCCESS [  1.014 s]
[INFO] my-modular-app-client .............................. SUCCESS [ 10.829 s]
[INFO] my-modular-app-server .............................. SUCCESS [  1.170 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.341 s
[INFO] Finished at: 2015-02-22T12:55:14+01:00
[INFO] Final Memory: 27M/257M
[INFO] ------------------------------------------------------------------------

Aftwerwards,我重构了项目结构,以便每个客户端,服务器,共享拥有它自己的子包。

  1. 检查)重构项目my-modular-app-shared:

    • 重命名包com.example.my.modular.app - > com.example.my.modular.app.shared
    • 从com.example.my.modular.app.MyModularAppFactory - >替换服务器的pom.xml引用。 com.example.my.modular.app.shared.MyModularAppFactory
    • 成功执行mvn clean install -Dgwt.draftCompile。
  2. 检查)重构项目my-modular-app-server:

    • 重命名包com.example.my.modular.app - > com.example.my.modular.app.server
    • 更新GreetingResponseProxy的@ProxyForName(“com.example.my.modular.app.GreetingResponse”) - > @ProxyForName( “com.example.my.modular.app.server.GreetingResponse”)
    • 更新GreetingContext的@ServiceName(“com.example.my.modular.app.GreetingService”) - > @ServiceName( “com.example.my.modular.app.server.GreetingService”)
    • 成功执行mvn clean install -Dgwt.draftCompile。
  3. 失败)重构项目my-modular-app-client:

    • 重命名包com.example.my.modular.app - > com.example.my.modular.app.client
    • 更新客户端的MyModuleApp.gwt.xml com.example.my.modular.app.MyModularApp - > com.example.my.modular.app.client.MyModularApp
    • 更新客户端pom.xml的gwt-maven-plugin模块条目com.example.my.modular.app.MyModularApp - > com.example.my.modular.app.client.MyModularApp
  4. [INFO] Compiling module com.example.my.modular.app.client.MyModularApp
    [INFO]    Tracing compile failure path for type 'com.example.my.modular.app.client.MyModularApp'
    [INFO]       [ERROR] Errors in 'file:/private/tmp/mvn/my-modular-app/my-modular-app-client/src/main/java/com/example/my/modular/app/client/MyModularApp.java'
    [INFO]          [ERROR] Line 41: No source code is available for type com.example.my.modular.app.shared.MyModularAppFactory; did you forget to inherit a required module?
    [INFO]          [ERROR] Line 135: No source code is available for type com.example.my.modular.app.shared.GreetingResponseProxy; did you forget to inherit a required module?
    [INFO]          [ERROR] Line 125: No source code is available for type com.example.my.modular.app.shared.FieldVerifier; did you forget to inherit a required module?
    [INFO]    Finding entry point classes
    [INFO]       Tracing compile failure path for type 'com.example.my.modular.app.client.MyModularApp'
    [INFO]          [ERROR] Errors in 'file:/private/tmp/mvn/my-modular-app/my-modular-app-client/src/main/java/com/example/my/modular/app/client/MyModularApp.java'
    [INFO]             [ERROR] Line 41: No source code is available for type com.example.my.modular.app.shared.MyModularAppFactory; did you forget to inherit a required module?
    [INFO]             [ERROR] Line 135: No source code is available for type com.example.my.modular.app.shared.GreetingResponseProxy; did you forget to inherit a required module?
    [INFO]             [ERROR] Line 125: No source code is available for type com.example.my.modular.app.shared.FieldVerifier; did you forget to inherit a required module?
    [INFO]       [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO]
    [INFO] my-modular-app ..................................... SUCCESS [  0.180 s]
    [INFO] my-modular-app-shared .............................. SUCCESS [  0.999 s]
    [INFO] my-modular-app-client .............................. FAILURE [  5.156 s]
    [INFO] my-modular-app-server .............................. SKIPPED
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 6.473 s
    

    pom.xml中没有其他内容,并且需要更改源文件。所有Java编译都完美无缺。但是,最终结果是失败,因为GWT编译器(gwt-maven-plugin)在构建客户端软件包时似乎并不寻找客户端项目自己的包之外的源。因此,如果共享项目有自己的子包,而不是客户端的子包,则会导致 gwt-maven-plugin无法解析共享中的任何来源。

    因此,GWT编译器找不到共享下的任何内容。有趣的是,如果我将my-modular-app-shared中的包重命名为com.example.my.modular.app.client而不是com.example.my.modular.app.shared并更新引用,那么一切都可以作为一个魅力。

    在我看来,问题是gwt-maven-plugin仅限于客户端的包,所有其他引用的项目应该在客户端包的子包中包含所有GWT相关源。问题是,如何在遍历不同的maven模块时告诉GWT编译器查看不同的包?

    任何帮助/指示非常感谢,并提前感谢!

    PS:我设法通过在客户端项目中添加以下GWT模块(包com.example.my.modular.app)并在MyModularApp.gwt.xml中继承它来创建一个解决方法:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE module PUBLIC
      "-//Google Inc.//DTD Google Web Toolkit 1.6.4//EN"
      "http://google-web-toolkit.googlecode.com/svn/tags/2.4.0/distro-source/core/src/gwt-module.dtd">
    <module>
      <source path="shared"/>
    </module>
    

    所以重新解释一下这个问题:有一种自动实现方法,而不是需要声明人工模块吗?

1 个答案:

答案 0 :(得分:0)

这就是GWT的工作原理,编译器只能看到来自源路径的类,这是类路径的一个子集。

通常,人们将他们的gwt.xml放在com.example.my.modular.app包中,并将客户端和共享子包添加到源路径:

<source path="client"/>
<source path="shared"/>