Inherit external java source in GWT project

别说谁变了你拦得住时间么 提交于 2019-12-23 09:49:22

问题


I have an ENUM that is used on the server-side. I want to be ably to use this enum on the client side (GWT) aswell.

This is the structure:

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

se.mycomapny.web.gwtproject <-- The GWT project.
se.mycomapny.web.gwtproject.client

I have tried to add

<inherits name="se.mycompany.core.TheEnum"/>

to my gwtproject.gwt.xml file. But I get the following error message:

[ERROR] Unable to find 'se/mycompany/core/TheEnum.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?

I have tried to add the file TheEnum.gwt.xml to 'se/mycompany/core/' with the following context.

<module>
  <inherits name='com.google.gwt.user.User'/>
  <source path="TheEnum"></source>
</module> 

But it still complains about the same thing.

I'm guessing I need to add the se.mycompany.core.TheEnum to the classpath in build.xml somehow, but I dont know how or where.


回答1:


The "inherits" tag is used to import other modules, not individual classes. You could achieve what you want by creating a simple GWT module under the core package, and then inherit that module in the existing one:

Create a file called Core.gwt.xml under package se.mycompany.core with the following content:

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

Then in your existing module add:

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



回答2:


Better to add the enum in client package, i.e, "se.mycomapny.web.gwtproject.client". And from server side you can use this enum from client package.

Still you want it on server side only then, create a package "se.mycompany.core.shared", create Core.gwt.xml in package "se.mycompany.core".

Core.gwt.xml:

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

Now create TheEnum.java in package "se.mycompany.core.shared". And in your main gwt.xml file write below line,

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


来源:https://stackoverflow.com/questions/12688325/inherit-external-java-source-in-gwt-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!