How do you use JPA objects with GWT in a different project? - gwt

I'm new to GWT, and I'm setting up a project to hold the UI portion of a complicated application. The JPA data objects are defined in a separate project using MyBatis generated POJOs. Once I manually modify the JPA objects to include 'implements Serializable' (this is a separate problem I need to solve), the gwtc step in the build process can't continue because it needs the source code for the JPA object, but can't find them.
I've created the 'core' project's jar files so that it includes the source .java files, but this didn't work. I've tried adding a classpath element to the gwtc ant java call.
How can I make my UI project compile while keeping the JPA objects defined in a separate project?
Errors:
Buildfile: /Users/user/source/user_interface/build.xml
libs:
javac:
gwtc:
[java] Compiling module org.mysite.ui
[java] Validating newly compiled units
[java] [ERROR] Errors in 'file:/Users/user/source/user_interface/src/org/mysite/ui/client/MyService.java'
[java] [ERROR] Line 21: No source code is available for type org.mysite.core.model.Person; did you forget to inherit a required module?
[java] [ERROR] Errors in 'file:/Users/user/source/user_interface/src/org/mysite/ui/client/MyServiceAsync.java'
[java] [ERROR] Line 19: No source code is available for type org.mysite.core.model.Person; did you forget to inherit a required module?
[java] [ERROR] Errors in 'file:/Users/user/source/user_interface/src/org/mysite/ui/client/presenter/MainTabPresenter.java'
[java] [ERROR] Line 75: No source code is available for type org.mysite.core.model.Person; did you forget to inherit a required module?
[java] Scanning for additional dependencies: file:/Users/user/source/user_interface/src/org/mysite/ui/client/MyApp.java
[java] Computing all possible rebind results for 'org.mysite.ui.client.MyService'
[java] Rebinding org.mysite.ui.client.MyService
[java] Checking rule <generate-with class='com.google.gwt.user.rebind.ui.ImageBundleGenerator'/>
[java] [ERROR] Unable to find type 'org.mysite.ui.client.MyService'
[java] [ERROR] Hint: Previous compiler errors may have made this type unavailable
[java] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
[java] [ERROR] Errors in 'file:/Users/user/source/user_interface/src/org/mysite/ui/client/MyApp.java'
[java] [ERROR] Line 23: Failed to resolve 'org.mysite.ui.client.MyService' via deferred binding
[java] [ERROR] Cannot proceed due to previous errors
BUILD FAILED
/Users/user/source/user_interface/build.xml:39: Java returned: 1
Total time: 26 seconds
Ant gwtc target:
<target name="gwtc" depends="javac" description="GWT compile to JavaScript (production mode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<pathelement location="../core/src"/>
<path refid="project.class.path"/>
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<arg line="-war"/>
<arg value="web"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg line="${gwt.args}"/>
<arg value="org.mysite.ui.MyApp"/>
</java>
</target>

GWT has always had this problem.
The approach I have taken in the past is to make a .gwt.xml module in the other JAR including the JPA POJOs and putting the JPA annotation classes in an "emul" javax.persistence folder. This won't work w/ many providers that use lazy fetching of course, so Gilead (as mentioned in another answer here) will be needed.
Another way is to make copies of the JPA objects and just Dozer them before sending across RPC
Luckily, GWT 2.1 has solved this problem. Use Entity proxies and request factories. It works well.

Either use the new GWT 2.1 RequestFactory / EntityProxy approach, or
Better, ditch the JPA and use Objectify or Twig.
We use Objectify, because JPA is not a good fit for Datastore. JPA was created with SQL-based relational databases in mind, while GAE Datastore is an entirely different thing.
Google ported JPA layer to Datastore to lure in developers, pretending that Datastore is just a plain old SQL relational database. This later blows up in their faces once projects grow big.
You really need to understand the Datastore tradeoffs if you want to use AppEngine. JPA is not making you a favor here.

Your best bet if you want to serialize POJOs to GWT is to use Gilead http://noon.gilead.free.fr/gilead/
All you have to do on your POJO is extend LightEntity and implement Serializable
The tutorial is pretty straight forward in how to set up the RPC.

Related

Importing External JAR to Websphere Liberty? [NoClassDefFoundError]

I want to use this JSON parser in my JAX-RS application that runs on Websphere Liberty.
I have done the following:
1) Right-click on Project -> Properties -> Java Build Path -> Add External Jar -> C:\javalib\quick-json.jar
2) Added C:\javalib to enviroment variable CLASSPATH
3) Added fileset xml to serverl.xml
<library id="ExternalLibs">
<fileset dir="C:\javalib" includes="*.jar"/>
</library>
4) Unchecked 'Enable project specific settings' in 'Java Compiler'
5) Cleaned the Project
[EDIT]
I was initially creating a new instance and then I turned it into an #ApplicationScoped bean and injected it. Now I get this error:
The JNDI lookup failed for JNDI name java:module/ConsoleREST with the following Exception CNTR4007E: An error occurred creating the websphere.jaxrs.service.ConsoleREST interface for the ConsoleREST enterprise bean in the WebApiConsole.war module in the WebApiConsole application. The enterprise bean look up failed using the java:module/ConsoleREST JNDI name. Exception: com/json/parsers/JsonParserFactory.
CNTR4007E: An error occurred creating the websphere.jaxrs.service.ConsoleREST interface for the ConsoleREST enterprise bean in the WebApiConsole.war module in the WebApiConsole application. The enterprise bean look up failed using the java:module/ConsoleREST JNDI name. Exception: com/json/parsers/JsonParserFactory
The first step was enough to get it to compile. Now I'm getting what I learned to be a runtime error. I would appreciate help!
You also need a <classloader> element in your application definition in the server.xml, which references the shared library. For example,
<application id="myapp" name="My App" type="war" location="somewhere.war">
<classloader commonLibraryRef="ExternalLibs" />
</application>
Alternatively, if your application is the only user of the library, you could package it in the WEB-INF/lib folder of your war. (Putting it in WebContent/lib in Eclipse should accomplish this.)

Add maven dependencies of OSGi bundles to the Eclipse target platform

I have some OSGi-bundles (plain OSGi, no eclipse dependencies) and a maven build with pax runner that launches them in a Knopflerfish server.
The maven build and launching the bundles works perfectly fine but only via pax runner (mvn pax:provision).
For debugging the bundles it would be nice though to launch them directly from within eclipse, otherwise my breakpoints won't trigger (seems obvious, as pax:provision launches built jar-files that are not tied to eclipse anymore).
The MANIFEST.MF-file is built the usual maven-way, means using maven-bundle-plugin. Therefore launching the bundles directly from eclipse fails because the eclipse platform misses all that required external OSGi-bundles that maven gets doing it's maven magic.
Therefore I am looking for a way to set up my eclipse target platform somehow so that the OSGi-bundles from maven are automatically included and can be accessed from within the IDE for resolving the constraints at launch time.
I checked the target platform settings, but apparently one can only add specific jars and folders to it, not whole folder structures like it would require to use the whole local maven repository. If I need to update my target platform for every new dependency thats going to get really ugly (I'd wish I could do something like "add C:\Users\myprofile.m2\repository to target platform" and eclipse would just load what it needs).
While researching I found Eclipse Tycho but apparently this only compiles a target platform for building the bundles, but not for compiling and launching them from within the IDE. Next I found this site: http://andriusvelykis.github.io/pde-target-maven-plugin/ And this looks like exactly what I need. From the documentation it seems that this plugin is able to take the target platform that is compiled from eclipse tycho and write it to a file. Then I am able to import this file back into my IDE and use it as target platform.
The problem I have is, that the plugin quits with an error that I can't deduce (I turned on stacktraces for a more complete error message).
[ERROR] Failed to execute goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies (default-cli) on project orchestrator-parent: The parameters 'baseDefinition' for goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies are missing or invalid -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies (default-cli) on project orchestrator-parent: The parameters 'baseDefinition' for goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies are missing or invalid
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:220)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:46)
Caused by: org.apache.maven.plugin.PluginParameterException: The parameters 'baseDefinition' for goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies are missing or invalid
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:581)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:534)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:97)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
This is the configuration for the plugin:
<plugin>
<groupId>lt.velykis.maven</groupId>
<artifactId>pde-target-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>pde-target</id>
<goals>
<goal>add-pom-dependencies</goal>
</goals>
<configuration>
<baseDefinition>D:/platform.target</baseDefinition>
<outputFile>D:/platform-pde.target</outputFile>
</configuration>
</execution>
</executions>
</plugin>
I can see that the paths are correct because the platform-pde.target file is created, but it has the same content as the base file.
File content (just a standard target platform that I created and shared as the base file):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="OrchestratorPlatform" sequenceNumber="8">
<locations>
<location path="${eclipse_home}" type="Profile"/>
</locations>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
<nl>en_US</nl>
</environment>
<launcherArgs>
<vmArgs>-Dosgi.requiredJavaVersion=1.6 -Xms40m -Xmx512m</vmArgs>
</launcherArgs>
</target>
What I am looking for are tips on how to configure the plugin correctly or any other ways I can bring my maven dependency bundles into my target platform so that I can launch the bundles directly from eclipse without having to maintain the dependencies somewhere in the depths of eclipse preferences again.
You can give a try to run PAX with defining vm options for your test container. By default the container is started in a separate JVM, and you can define command line options for it. In the documentation even you will find an example to start the tests in debug mode. Just define suspend=y, and you will have enough time to attach your Eclipse with a remote debugging session.
There is also an eclipse plugin for Pax Runner, you can try that.
EDIT:
With the launch config you sent me in the comment, you debugged the maven JVM, and not the OSGI container.
It is tricky to find documentation for pax:provision. I tried help:describe:
C:\>mvn help:describe -Dplugin=org.ops4j:maven-pax-plugin:1.5 -Dgoal=provision -Ddetail
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:describe (default-cli) # standalone-pom ---
[INFO] Mojo: 'pax:provision'
pax:provision
Description: Provision all local and imported bundles onto the selected
OSGi framework
mvn pax:provision [-Dframework=felix|equinox|kf|concierge] [-Dprofiles=log,war,spring,...]
If you don't have Pax-Runner in your local Maven repository this command
will automatically attempt to download the latest release. It will then
continue to use this locally installed version of Pax-Runner unless you add
-U to force it to check online for a later release, or -Drunner=version to
temporarily use a different version.
Implementation: org.ops4j.pax.construct.lifecycle.ProvisionMojo
Language: java
Available parameters:
args
User property: args
URL of file containing additional Pax-Runner arguments.
deploy (Default: true)
User property: deploy
When true, start the OSGi framework and deploy the provisioned bundles.
deployPoms
User property: deployPoms
Comma separated list of additional POMs with bundles as dependencies.
deployURLs
User property: deployURLs
Comma separated list of additional bundle URLs to deploy.
framework
User property: framework
Name of the OSGi framework to deploy onto.
noDependencies
User property: noDeps
Ignore bundle dependencies when deploying project.
profiles
User property: profiles
Comma separated list of additional Pax-Runner profiles to deploy.
provision
User property: provision
A set of provision commands for Pax-Runner.
runner (Default: RELEASE)
User property: runner
The version of Pax-Runner to use for provisioning.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.570s
[INFO] Finished at: Wed Feb 19 00:01:05 CET 2014
[INFO] Final Memory: 8M/109M
[INFO] ------------------------------------------------------------------------
So as it seems:
Create a file containing the following text:
--vmOptions=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8888
Run your build like this:
mvn pax:provision -Dargs=file:///c:/yourfilepath/thefilecontainingstuffabove.txt
I did not try it, but it can work. Suspends, port 8888, Eclipse Remote Debug :)
I am using remote debugging with Apache Karaf a lot. There karaf also loads the bundles from the maven repository.
Still eclipse finds the breakpoints and triggers them. So the same should work for pax runner.
What I do is to export KARAF_DEBUG=true and start karaf. This triggers the typical remote debugging settings which should also be available for pax runner. I then start a remote debug session from eclipse and simply add all necessary open eclipse projects to the sources of the remote debug session. This works almost all of the time. Sometimes my breaktpoints are also not triggered but it is very seldom and I did not find out why.
Btw. Karaf also allows to update bundles from the local maven repo while running. So if you change a project you can simply call mvn clean install on the single bundle project, do "update bundleid" on the shell and can continue to debug with the new version of the bundle. This is extremely helpful when you got a large project but only work at a small part while debugging.
So to resume you should be able to use pax runner with remote debugging without problems and it might also be interesting to take a look at apache karaf.

Compiling GWT project using GUICE with ANT

I can successfully compile the source, but when I hit this ant task:
<target name="gwtc" depends="javac" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg line="${gwt.args}"/>
<arg value="com.jwavro.jaguar.jaguar"/>
</java>
</target>
I'm getting these errors:
gwtc:
[java] Compiling module com.jwavro.jaguar.jaguar
[java] Scanning for additional dependencies: generated://9161C2B729E3521B2A51CBE6F2AE8A77/com/unnison/framework/client/GeneratedGinInjector.java
[java] Computing all possible rebind results for 'com.unnison.framework.client.GeneratedGinInjector'
[java] Rebinding com.unnison.framework.client.GeneratedGinInjector
[java] Invoking generator com.google.gwt.inject.rebind.GinjectorGenerator
[java] [ERROR] Generator 'com.google.gwt.inject.rebind.GinjectorGenerator' threw an exception while rebinding 'com.unnison.framework.client.GeneratedGinInjector'
[java] com.google.inject.CreationException: Guice creation errors:
[java]
[java] 1) No implementation for javax.inject.Provider was bound.
[java] while locating javax.inject.Provider
[java] for parameter 9 at com.google.gwt.inject.rebind.BindingsProcessor.(BindingsProcessor.java:209)
[java] at com.google.gwt.inject.rebind.GinjectorGeneratorModule.configure(GinjectorGeneratorModule.java:59)
GUICE binding is supposed to be automatic, any idea how to fix it ?
Guice can not be used directly with GWT. You need to use GIN.
javax.inject is a dependency that needs to be in your classpath.
If you downloaded Guice from Google, there should be a lib folder in the exploded zip with a javax.inject.jar file, or you can download it direct from trunk.
The key is this line:
[java] 1) No implementation for javax.inject.Provider was bound.
There are two things I can think of. First of all make sure you have properly inherited the GIN module in your GWT module xml:
<module>
...
<inherits name="com.google.gwt.inject.Inject"/>
...
</module>
Secondly you have to be carefull about versions of GIN and Guice. On the GIN homepage it says:
GIN 1.0 requires ... and Guice 2.0
For Gin 1.5 you'll need to use the Guice snapshot distributed with Gin or ... Guice 3.0
So make sure you have the appropriate Guice JAR in path.

How to include an external jar in a GWT module?

I would like to use the org.apache.commons.validator.GenericValidator class in a view class of my GWT web app. I have read that I have to implicitely tell that I intend to use this external library. I thought adding the next line into my App.gwt.xml would work.
<inherits name='org.apache.commons.validator.GenericValidator'/>
I get the next error:
Loading inherited module 'org.apache.commons.validator.GenericValidator'
[ERROR] Unable to find 'org/apache/commons/validator/GenericValidator.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] Line 13: Unexpected exception while processing element 'inherits'
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:239)
at com.google.gwt.dev.cfg.ModuleDefSchema$BodySchema.__inherits_begin(ModuleDefSchema.java:354)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.util.xml.HandlerMethod.invokeBegin(HandlerMethod.java:223)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.startElement(ReflectiveParser.java:270)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1339)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.parse(ReflectiveParser.java:327)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.access$100(ReflectiveParser.java:48)
at com.google.gwt.dev.util.xml.ReflectiveParser.parse(ReflectiveParser.java:398)
at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:257)
at com.google.gwt.dev.cfg.ModuleDefLoader$1.load(ModuleDefLoader.java:169)
at com.google.gwt.dev.cfg.ModuleDefLoader.doLoadModule(ModuleDefLoader.java:283)
at com.google.gwt.dev.cfg.ModuleDefLoader.loadFromClassPath(ModuleDefLoader.java:141)
at com.google.gwt.dev.Compiler.run(Compiler.java:184)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:152)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:87)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:81)
at com.google.gwt.dev.Compiler.main(Compiler.java:159)
[ERROR] Failure while parsing XML
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.util.xml.DefaultSchema.onHandlerException(DefaultSchema.java:56)
at com.google.gwt.dev.util.xml.Schema.onHandlerException(Schema.java:66)
at com.google.gwt.dev.util.xml.Schema.onHandlerException(Schema.java:66)
at com.google.gwt.dev.util.xml.HandlerMethod.invokeBegin(HandlerMethod.java:233)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.startElement(ReflectiveParser.java:270)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1339)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.parse(ReflectiveParser.java:327)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.access$100(ReflectiveParser.java:48)
at com.google.gwt.dev.util.xml.ReflectiveParser.parse(ReflectiveParser.java:398)
at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:257)
at com.google.gwt.dev.cfg.ModuleDefLoader$1.load(ModuleDefLoader.java:169)
at com.google.gwt.dev.cfg.ModuleDefLoader.doLoadModule(ModuleDefLoader.java:283)
at com.google.gwt.dev.cfg.ModuleDefLoader.loadFromClassPath(ModuleDefLoader.java:141)
at com.google.gwt.dev.Compiler.run(Compiler.java:184)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:152)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:87)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:81)
at com.google.gwt.dev.Compiler.main(Compiler.java:159)
[ERROR] Unexpected error while processing XML
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.parse(ReflectiveParser.java:351)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.access$100(ReflectiveParser.java:48)
at com.google.gwt.dev.util.xml.ReflectiveParser.parse(ReflectiveParser.java:398)
at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:257)
at com.google.gwt.dev.cfg.ModuleDefLoader$1.load(ModuleDefLoader.java:169)
at com.google.gwt.dev.cfg.ModuleDefLoader.doLoadModule(ModuleDefLoader.java:283)
at com.google.gwt.dev.cfg.ModuleDefLoader.loadFromClassPath(ModuleDefLoader.java:141)
at com.google.gwt.dev.Compiler.run(Compiler.java:184)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:152)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:87)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:81)
at com.google.gwt.dev.Compiler.main(Compiler.java:159)
I have commons.validator-1.3.1.jar in war/WEB-INF/lib
I am using eclipse with Google Plugin.
Anyone knows how it works?
The syntax <inherits name='package.SomeModule'/> is only for special GWT modules, built to be used with GWT, not generics Java libraries (docs). A quick test to see if a jar/library is built to be used with GWT is to see if it includes a module file. If you look at the error you posted the top line reads:
Loading inherited module 'org.apache.commons.validator.GenericValidator'
[ERROR] Unable to find 'org/apache/commons/validator/GenericValidator.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
You can see that commons.validator is missing the required module file. You can still use this library on the server side (no restrictions there). For client side, chances are GWT doesn't emulate the required parts of Java - for more information see the docs.
Alternatively you can add the GWT module XML file to your project. I've had to do this in the past.
This is not "ideal", but it saves you from having to repackage the jars.
In this case, you could create a file named "Commons.gwt.xml" and put it in a /org/apache/commons directory in your local source path. The file would contain:
<module>
<source path="validator"/>
</module>
Then, you would just need to add the line <inherits name="org.apache.commons.Common"> to your application.
What you would need to do if this was your library would be to add in a XXX.gwt.xml file for each package that you want GWT to be able to compile to. This is how you would add in a shared jar for instance into a GWT frontend of a multi-tiered (and multi-server) app. You can take any of the GWT libraries and unzip their jars to see what I mean, there will be a file called XXX.gwt.xml one level above all packages that GWT needs to be able to use to compile.
In the past I have taken and re-packaged some of these open source libraries, which you could do here. This is problematic since then you really need to source control your version of the library, and would have to manually merge any new changes (or just redo the XXX.gwt.xml file entries and repackage).
So this is not the best case scenario (but sometimes you're looking for miss right now and not miss right), is there no way around this just using core GWT and Java? I know the pre-fab libraries are great, but is the dependency with the extra work worth the time savings in you particular case?
I hope that helps.

GWT 3rd Party Library Problem : Code Included

I am using Eclipse Version: 3.5.1, GWT 2.0.0, GAE 1.3.0 and I am trying to use XStream 1.3.2 to 'serialize' my Java objects to and from xml between the client and server sides of GWT.
On the server side, XStream works without issue.
On the client side, the compiler complains that it cannot find source code for the XStream classes used. I understand that this is some sort of 'referencing' issue where GWT client classes cannot automatically find server classes and I understand why this is however, I am going slowly insane as I try to use the approaches described in various articles and tutorials that cover how to use 3rd party libraries in GWT.
None of them work!
My gwt.xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.1/distro-source/core/src/gwt-module.dtd">
<module rename-to='bandmates'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- 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'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='org.redboffin.bandmates.client.BandMates' />
</module>
My Eclipse XStream Library is as follows:
XStream
|__ Access rules : No rules defined
|__ Native library location: (None)
|__ xstream-1.3.2.jar [path to jar]
|__ Source Attachment: xstream-1.3.2-sources.jar [path to source jar]
|__ Javadoc location: [path to javadoc]
|__ Native library location: (None)
|__ Access rules : No restrictions
I am more familiar with Netbeans and so I may be setting this up incorrectly, but I think I have included XStream into my Eclipse GWT project as a third party library and have correctly referenced the binary jar, the source jar and the javadoc jar
The client side method that throws the error:
public void onSuccess(String profilesXml) {
// Deserialize the xml
XStream xstream = new XStream(new DomDriver());
ProfilesImpl profiles = (ProfilesImpl) xstream.fromXML(profilesXml);
// Show the RPC result to the user
this.friendsWidget.setFriendProfiles(profiles);
this.friendsWidget.update();
}
And the GWT Compiler error:
Compiling module org.redboffin.bandmates.BandMates
Validating newly compiled units
[ERROR] Errors in 'file:/C:/Documents%20and%20Settings/Darren/workspace/BandMates/src/org/redboffin/bandmates/client/widgets/FriendsWidget.java'
[ERROR] Line 63: No source code is available for type com.thoughtworks.xstream.XStream; did you forget to inherit a required module?
[ERROR] Line 63: No source code is available for type com.thoughtworks.xstream.io.xml.DomDriver; did you forget to inherit a required module?
Finding entry point classes
[ERROR] Unable to find type 'org.redboffin.bandmates.client.BandMates'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
I'm not sure what other information you may need to help me but if you need something I haven't provided then please ask.
Thanks for reading this far :-)
Don't you need to import your XStreams package in your gwt.xml file. E.g. something like:
<inherits name='com.thoughtworks.xstream'/>
?
GWT compiles Java source to JavaScript. You canĀ“t just point to a regular jar. If you really must use XStream, you will need to include the sources under the client package or create a separate module and import it.
But for me this is just reinvent the wheel. You will have a lot of work and it will be slower than RPC. Even if there are other clients using the XML output, maybe you should consider having both ways.