【发布时间】:2017-05-18 18:40:53
【问题描述】:
我创建了一个具有以下结构的 GWT Maven 多模块项目。
核心模块 [包含活动、演示者、共享资源] 带有入口点的 core.gwt.xml
core.gwt.xml
<inherits name='com.google.gwt.user.User' />
<!-- We need the JUnit module in the main module, -->
<!-- otherwise eclipse complains (Google plugin bug?) -->
<!--<inherits name='com.google.gwt.junit.JUnit' /> -->
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<!--inherits name='com.google.gwt.user.theme.standard.Standard' /> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- <stylesheet src="styles-global.css"/> -->
<!--GWT-QUERY -->
<!-- <inherits name='com.google.gwt.query.Query'/> -->
<!--SuperDev Mode -->
<!-- add-linker name="xsiframe"/> <set-configuration-property name="devModeRedirectEnabled"
value="true"/-->
<set-property name="user.agent" value="gecko1_8,safari" />
<!-- Other module inherits -->
<!-- We need the MVP stuff (Activity and Place -->
<!-- I am also using DepInj with Gin (Inject) -->
<!-- and Resource for client bundle and stuff (not used yet) -->
<inherits name="com.google.gwt.activity.Activity" />
<inherits name="com.google.gwt.place.Place" />
<inherits name="com.google.gwt.inject.Inject" />
<inherits name="com.google.gwt.resources.Resources" />
<inherits name="com.google.gwt.user.Debug" />
<inherits name="org.fusesource.restygwt.RestyGWT"/>
<!-- gwtbootstrap3 -->
<inherits name="com.template.resources.CustomBootstrap"/>
<!-- Specify the app entry point class. -->
<entry-point class='com.template.core.client.template' />
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
<!-- Form Factors -->
<inherits name="com.template.core.FormFactor" />
<!-- For JSON Ajax call -->
<inherits name="com.google.gwt.http.HTTP" />
<!-- For Logging Framework src: https://developers.google.com/web-toolkit/doc/latest/DevGuideLogging -->
<inherits name="com.google.gwt.logging.Logging" />
<set-property name="gwt.logging.enabled" value="FALSE" />
<define-configuration-property name="gin.ginjector"
is-multi-valued="false" />
<set-configuration-property name='gin.ginjector'
value='com.template.core.client.ioc.ClientGinjector' />
<!-- gwt dnd -->
<inherits name='com.allen_sauer.gwt.dnd.gwt-dnd'/>
桌面模块[包含具有桌面特定视图的桌面模块] desktop.gwt.xml 带有入口点
desktop.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<inherits name='com.template.core.template' />
<entry-point class='com.template.desktop.client.desktoptemplate' />
<source path='client' />
Tablet Module [包含带有特定于平板电脑视图的平板电脑模块] 带有入口点的 tablet.gwt.xml
移动模块 [包含具有移动特定视图的移动模块] 带有入口点的 mobile.gwt.xml
台式机、平板电脑和移动设备依赖于核心模块。我也继承了设备模块中的core模块,提到了设备模块中core的依赖
我可以在 Eclipse 中完美地使用 google gwt 插件单独运行这些模块。但是当我在根项目上执行 maven 安装时,核心模块的入口点没有被找到并抛出异常。
[错误] 找不到类型“com.template.core.client.template” [INFO] [ERROR] 提示:检查类型名称 'com.template.core.client.template' 是否真的是您的意思 [INFO] [ERROR] 提示:检查您的类路径是否包含所有必需的源根目录 [信息] [错误]“文件:/home/software/mmt/template_ui/template_ui_desktop/src/main/java/com/template/desktop/client/desktoptemplate.java”中的错误 [INFO] [ERROR] 第 20 行:com.template.core.client.ioc.ClientGinjector 类型没有可用的源代码;你忘了继承一个必需的模块吗? [INFO] [ERROR] 第 21 行:没有可用于类型 com.template.core.client.application.main.ServletURL 的源代码;你忘了继承一个必需的模块吗? [信息] [错误] 找不到类型“com.template.desktop.client.desktoptemplate” [INFO] [ERROR] 提示:以前的编译器错误可能导致此类型不可用 [INFO] [ERROR] 提示:检查模块的继承链;它可能没有继承所需的模块,或者模块可能没有正确添加其源路径条目
[INFO] 模板用户界面 ................................... ......................成功 [ 1.374 秒] [信息] 核心模块 ................................................... ...................... 成功 [ 46.110 秒] [信息] 桌面模块.................................................................. .....................失败 [ 23.713 秒] [INFO] 平板电脑模块.................................................................. …………………………………………………………………………………………………………………………………… .......跳过 [信息] 移动模块 ................................................... ..................................................... .....跳过
解决方案
gwt 库应该同时包含 .java 和 .class 文件。所以我们需要打包这两个文件(你也可以有 .css、.png、.html 等文件)。您可以使用下面的 pom.xml 配置来包含它们。
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.ui.xml</include>
<include>**/*.java</include>
<include>**/*.gwt.xml</include>
<include>**/*.html</include>
<include>**/*.js</include>
<include>**/*.css</include>
<include>**/*.gif</include>
<include>**/*.jpg</include>
<include>**/*.png</include>
</includes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.ui.xml</include>
<include>**/*.java</include>
<include>**/*.gwt.xml</include>
<include>**/*.html</include>
<include>**/*.js</include>
<include>**/*.css</include>
<include>**/*.gif</include>
<include>**/*.jpg</include>
<include>**/*.png</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
我在核心的 pom.xml 中使用了这个配置
【问题讨论】:
-
没有更多关于你的
*.gwt.xml和pom.xml的信息看起来很难猜,但我怀疑你错过了在desktop.gwt.xml中导入相关模块 -
我已将核心模块 core.gwt.xml 导入到 desktop.gwt.xml 中,并带有继承标签。但我仍然面临这个问题。我认为核心的 src 文件夹没有进入桌面的类路径。
-
你能确认确实有一个名为'template
, lowercase and all, in thecom.template.core.client`包的类吗?另外,日志中是否有任何早期的错误消息? -
感谢您的回复,科林·阿尔沃斯。我通过使用 .java 和 .class 文件打包核心 jar 解决了这个问题。因为 gwt 库应该同时具有 .class 和 .java 文件。 Thomas Broyer 在这篇文章中给出了解决方案stackoverflow.com/a/22835683/3548310(@Thomas Broyer 真棒)
标签: java maven gwt multi-module