Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在GWT项目中继承外部java源代码_Java_Gwt_Inheritance - Fatal编程技术网

在GWT项目中继承外部java源代码

在GWT项目中继承外部java源代码,java,gwt,inheritance,Java,Gwt,Inheritance,我有一个在服务器端使用的枚举。 我也希望能够在客户端(GWT)上使用这个枚举 结构如下: se.mycompany.core se.mycompany.core.TheEnum <-- this Enum. se.mycomapny.web.gwtproject <-- The GWT project. se.mycomapny.web.gwtproject.client se.mycompany.core se.mycompany.core.TheEnum使用“inherits

我有一个在服务器端使用的枚举。 我也希望能够在客户端(GWT)上使用这个枚举

结构如下:

se.mycompany.core
se.mycompany.core.TheEnum <-- this Enum.

se.mycomapny.web.gwtproject <-- The GWT project.
se.mycomapny.web.gwtproject.client
se.mycompany.core
se.mycompany.core.TheEnum使用“inherits”标记导入其他模块,而不是单个类。通过在
core
包下创建一个简单的GWT模块,然后在现有模块中继承该模块,您可以实现您想要的:

在package
se.mycompany.Core
下创建一个名为
Core.gwt.xml
的文件,包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<module>
    <source path="" includes="TheEnum.java"/>    
</module>

然后在现有模块中添加:

<inherits name='se.mycompany.core.Core'/>

最好在客户端包中添加enum,即“se.mycomapny.web.gwtproject.client”。从服务器端,您可以使用客户机包中的枚举

但您仍然希望它只在服务器端,然后创建一个包“se.mycompany.core.shared”,在包“se.mycompany.core”中创建core.gwt.xml

Core.gwt.xml:

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

现在在包“se.mycompany.core.shared”中创建TheEnum.java。在主gwt.xml文件的下面一行中

<inherits name='se.mycompany.core.Core'/>


仍然会遇到“在类路径上找不到'se/mycompany/core/core.gwt.xml';可能是输入错误,或者可能是您忘了包含源的类路径条目?”请仔细检查您的文件路径和包名。我已经多次使用类似的设置,它对我很有效。如果您使用maven将*.gwt.xml文件编译到jar中,您可能会发现您的jar缺少xml文件。查看以下线程以获得修复:除了David的答案之外,请绝对确保您的jar包含.java文件。GWT需要将.java文件翻译成javascript。我的jar最初不包含这些文件,我会看到错误:“没有可用于type的源代码;您是否忘记继承所需的模块?“即使gwt能够看到我的gwt.xml文件。强迫maven将.java文件保存在我的jar中修复了这个问题。
<module>
<source path="shared"/>
</module>
<inherits name='se.mycompany.core.Core'/>