How can share bean from external library to GWT client? - java

I have a question about share the java bean in library to gwt client
I know bean share between GWT client and server usually put into package domain.shared.
However, how can I make use of existing bean from external jar library on GWT client?
Because I always got this message.
No source code is available for type xxxx.xxxx.bean did you forget to inherit a required module?

Given that your beans are in the package xxx.xxx.bean, and they are in an imported my_beans.jar library.
Create a folder in your Application src tree (or src/main/java if you are using maven) with the name xxx/xxx
Create a new Module file in this folder called MyBeans.gwt.xml with this content:
<module>
<inherits name='com.google.gwt.user.User'/>
<source path="bean"/>
</module>
Edit your Application.gwt.xml and add this line
<inherits name="xxx.xxx.MyBeans"/>
Be aware that all Classes in the xxx.xxx.bean package must use classes supported by GWT.
You should check as well that the my_beans.jar library includes the java source files of the beans you are going to use.

1) You can only include beans from the external jar library provided it is GWT compatible and declares a <ThirdPartyModuleName>.gwt.xml file which includes the package for the beans you need to use.
2) You should have the <ThirdPartyModuleName> included in your own <Module>.gwt.xml using <inherits> tag.

Related

Add a ResourceBundle service provider directive in a Java 13 module through moditect maven plugin

I got a Java project that I'm migrating from Java 8 to Java 13. This project uses ResourceBundles to enable language localisation.
In Java 8, I provided a custom ResourceBundle.Control to ResourceBundle.getBundle(baseName, control) but this doesn't work anymore in Java 9+. As I understand it, I must instead provide a custom ResourceBundleProvider interface, which I called UiProvider, and an implementation of this interface, UiProviderImpl, which must be used as a service.
To generate module descriptors, I'm using the moditect maven plugin. But it doesn't look like I can add a provides directive anywhere, only exports, opens and uses directives. Or am I missing anything? Here's an excerpt of my pom.xml with what I tried to configure. Can this be fixed?
<module>
<moduleInfo>
<name>net.babelsoft.negatron</name>
<opens>net.babelsoft.negatron;</opens>
<uses>theme.language.spi.UiProvider</uses>
<provides>theme.language.spi.UiProvider with theme.language.spi.UiProviderImpl</provides>
</moduleInfo>
</module>
At the time I wrote my question, Moditect didn't support the provides directive within the moduleInfo tag.
The only way was to use a moduleInfoSource tag, which forces the developper to directly write the actual content of module-info.java, not very satisfactory.
After discussing with the author of Moditect, I submitted a pull request to add the support of the provides directive within the moduleInfo tag. It hasn't been merged to Moditect source code yet...

JAXB package-info.java declarations are ignored in separate maven modul

I use package-info.java to specify #XmlAccessorType(XmlAccessType.NONE) and some xml java adapters using #XmlJavaTypeAdapters. Model objects (with JAXB annotations) are placed in separate maven module shared by other modules. The configuration in package-info.java is not discovered if model objects are in separate maven module. If I move for testing purposes model objects to same maven module everything is OK. I think separate maven module can be considered equivalent to 3rd party lib from JAXBContext point of view. I use JDK1.7 JAXB reference implementation. Any ideas how configuration may differ?
I also encounter this problem, in my case qualified/unqualified property from package-info.java was ignored. I managed to find two way to workaround this:
like Pavla wrote, copy all JAXB classes with package-info.java locally
include module as a dependency with compile scope (which gives similar result that classes are in module. In my case I created separate jar lib with JAXB classes)
I also spotted that it do not work only in case of creating WebServices (creating object and sending to WS works fine in different modules).
I am using Jbossas7.1.1 and cxf 2.4.6. In the time of registering service Jboss created wsdl from JAXB (in my case path /opt/jboss/jboss-as-7.1.1.Final/standalone/data/wsdl/module.war/SubmitMessage.wsdl). In local setting file is generated properly.
Any ideas why creating WS behaves like this?
I hit this issue recently and the actual problem (with Java 8, i.e. no Java modules involved) was that I had on the classpath two *.jar files which both contained the same package - in one JAR, there was package-info.class with JAXB annotations and in the other one, there wasn't.
In that case, I guess that if package-info.class file is discovered depends on the classpath ordering (which is very brittle and only semi-deterministic).

Error inheriting a module in a mavenized GWT project

After adding this dependency in my pom.xml:
<dependency>
<groupId>com.eaio.uuid</groupId>
<artifactId>uuid</artifactId>
<version>3.2</version>
</dependency>
I get an error by jetty on the module load event:
no source code available for com.eaio.uuid; did you forget to inherit the module? unable to find com.client.myproject..`
What am I missing?
If you're using any of the classes in that artifact in your GWT compiled code, then the source code needs to be available, either packaged in the jar or as a source jar (remember that's another dependency).
You'll have to look for a .gwt.xml file in the jar, as this will be the name you need to inherit in your own GWT descriptor, eg. if the file is called com/eaio/UUID.gwt.xml you should
...
<inherits name="com.eaio.UUID" />
...
If one isn't available, just create your own with a simple <source path="..." /> and stick in the right package in your own project (still provided the source is actually available!)
Cheers,

Unable to compile the com.google.gwt.thirdparty.guava.common.base.Optional package of gwt-dev jar

I would like to use the Optional class of guava jar. I am able to use it in my project.But, in the gwt-dev jar the Optional class has already been there in the package com.google.gwt.thirdparty.guava.common.base.Optional. So, I don't want to use the guava jar for just using the Optional class. So, I am trying to use the Optional class of gwt-dev jar.
Steps which I have done:
I have created com.google.gwt.thirdparty.guava.common.base package in my project
In that package I have created the Base.gwt.xml file.
<?xml version="1.0" encoding="utf-8"?>
<!-- semi-autogenerated module descriptor -->
<module>
<source path="">
</source>
</module>
I have included the Base.gwt.xml file in my gwt.xml file.
Though I have done the above steps I was not able to compile the code. I am getting the below exception:
No source code is available for type com.google.gwt.thirdparty.guava.common.base.Optional; did you forget to inherit a required module?
Any suggestions would be appretiated.
You shouldn't be using com.google.gwt.thirdparty.* - those are internally repackaged jars. There's no guarantee they'll be there in the next version of GWT - in fact, I'd expect them (at least the Guava part) to be removed in favor of "vanilla" Guava, as suggested in this thread. To further reinforce this there's no source attached for them in the gwt-dev.jar (as you've experienced), so you can't use them in your client-side code.
Please use the normal dependency on Google Guava - the GWT compiler will only compile in the parts of Guava that you are using (especially if you just inherit com.google.common.base.Base) and prune out the rest.

Unable to compile the GWT module while trying to use javax.annotation.Nullable?

I would like to use the javax.annotation.Nullable annotation in my GWT project. I would like to know which module has to be inherited into my gwt.xml file inorder to use that annotation. The google guava jar internally uses the Nullable annotation and If I use that Jar in my project it is able to compile. Please help me what package has to be inherited inorder to use the javax.annotation.Nullable annotation?
I have been searching on net for long time, but still unable to figure out which package has to be inherited.
Any suggestions would be appretiated.
You have to add a dependency on JSR 305. For example, Guava uses this:
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
Now, you have to use a workaround mentioned in a issue:
Create a simple javax/annotation/Annotation.gwt.xml file in your project:
<module>
<source path="" />
</module>
Add <inherits name='javax.annotation.Annotation' /> to your applications module (.gwt.xml) file.

Categories