5

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.

brange
  • 270
  • 4
  • 16

2 Answers2

6

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'/>
David Levesque
  • 22,181
  • 8
  • 67
  • 82
  • Still getting "Unable to find 'se/mycompany/core/Core.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?" – brange Oct 03 '12 at 07:06
  • Double check your file paths and package names. I've used a similar setup many times and it works for me. – David Levesque Oct 03 '12 at 17:22
  • If you're compiling your *.gwt.xml file into a jar using maven, you might find your jar missing the xml file. See the following thread for a fix: https://stackoverflow.com/questions/9798955/with-maven-clean-package-xml-source-files-are-not-included-in-classpath – Jake88 May 26 '17 at 21:20
  • In addition to David's answer, make absolutely sure that your jar contains the .java files. GWT needs the .java files to translate into javascript. My jar did not contain these files originally and I would see the error: 'No source code is available for type ; did you forget to inherit a required module?' even though gwt was able to see my gwt.xml file. Forcing maven to keep the .java files in my jar fixed the problem. – Jake88 May 28 '17 at 16:33
  • Re. "...make absolutely sure that your jar contains the .java files...": Do these have to be in the very same .jar file as the .class-files or is it enough to add the corresponding xyz-sources.jar to the dependencies? I tried the latter and am banging my head against the wall, why this darn compiler doesn't find them... – mmo Jul 21 '22 at 19:27
0

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'/>
vbjain
  • 547
  • 2
  • 7
  • 23