GWT compile POJO - gwt

I'm trying to use just the Java to Javascript compiler of the GWT from Ant.
Can I use the GWT compiler without extending any Google classes such as com.google.gwt.core.Core or similar. If so how? I'm currently using the setup below on GWT 2.4.0.
I'm calling the ant task:
build.xml
<target name="gwtc" description="GWT compile to JavaScript (production mode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="${gwt.sdk}/validation-api-1.0.0.GA.jar" />
<pathelement location="${gwt.sdk}/validation-api-1.0.0.GA-sources.jar" />
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<arg line="-war"/>
<arg value="war"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg line="${gwt.args}"/>
<arg value="foo.Test1"/>
</java>
</target>
foo/Test.java
package foo;
public class Test1 {
public String field1;
public String field2;
public int field3;
}
foot/Test1.gwt.xml
<module rename-to="hello">
<source path="foo.Test1"/>
<!--entry-point class="foo.Test1"/-->
</module>
And output:
gwtc:
[java] Compiling module foo.Test1
[java] [ERROR] Unable to find type 'java.lang.Object'
[java] [ERROR] Hint: Check that your module inherits 'com.google.gwt.core.Core' either directly or indirectly (most often by inheriting module 'com.google.gwt.user.User')

The error indicates that you need to inherit 'com.google.gwt.core.Core' in your gwt.xml file and it is not saying that your class should extend/implement it. Give this a try:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE
module
PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.3.0//EN"
"http://google-web-toolkit.googlecode.com/svn/tags/2.3.0/distro-source/core/src/gwt-module.dtd">
<module rename-to="hello">
<inherits name="com.google.gwt.core.Core" />
<source path="foo" />
</module>
Or is it that you don't want your module to inherit it?

Related

Running an Ant-builded project as web-application

I'm trying to run a "project.zip" I've downloaded from the official GWT site about RPC and Hibernate at http://www.gwtproject.org/articles/using_gwt_with_hibernate.html .
The guide suggests:
"you can use Ant to build the project, as well as start up hosted mode
to see the UI and our Hibernate instance setup in the embedded Jetty
server."
So I have imported it on Eclipse with New > Project menu-> Java Project from Existing Ant Buildfile wizard.
My final goal is to run it on Eclipse as web-application, but it gives me every types of errors and above all there's no run as-> web application but only as ->ant build ! And all the War directory is missing in Eclipse.
How can change this Ant build project.zip to a normal project GWT? I'm amazed how an official Google guide can give so many problems!
If you need it this is the build.xml :
<?xml version="1.0" encoding="utf-8" ?>
<project name="Guestbook" default="build" basedir=".">
<!-- Define gwt.home, gwt.dev.jar, appengine.sdk.home -->
<property file="build.properties"/>
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes"/>
<pathelement location="${gwt.home}/gwt-user.jar"/>
<!-- Add any additional non-server libs (such as JUnit) -->
<fileset dir="war/WEB-INF/lib">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="libs" description="Copy libs to WEB-INF/lib">
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib" file="${gwt.home}/gwt-servlet.jar" />
<!-- Add any additional server libs that need to be copied -->
<copy todir="war/WEB-INF/lib" flatten="true">
<fileset dir="lib/">
<include name="**/*.jar"/>
</fileset>
</copy>
</target>
<target name="javac" depends="libs" description="Compile java source">
<mkdir dir="war/WEB-INF/classes"/>
<javac srcdir="src" includes="**" encoding="utf-8"
destdir="war/WEB-INF/classes"
source="1.5" target="1.5" nowarn="true"
debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path"/>
</javac>
</target>
<!-- can add additional arguments like -logLevel INFO or -style PRETTY -->
<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"/>
<pathelement location="${gwt.home}/${gwt.dev.jar}"/>
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<arg value="com.google.musicstore.MusicStore"/>
</java>
</target>
<target name="hosted" depends="javac" description="Run hosted mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.HostedMode">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="${gwt.home}/${gwt.dev.jar}"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="-startupUrl"/>
<arg value="MusicStore.html"/>
<arg value="com.google.musicstore.MusicStore"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
</java>
</target>
<target name="build" depends="gwtc" description="Build this project" />
<target name="clean" description="Cleans this project">
<delete dir="war/WEB-INF/classes" failonerror="false" />
<delete dir="war/musicstore" failonerror="false" />
</target>
</project>
run
ant
to build the project.
run
ant hosted
to run the project.
I'm confused by the concept of a normal GWT project ... I'm not sure to understand what it means. But if it means an eclipse-ready-GWT-project, you will probably be disappointed because as you noted yourself:
you can use Ant to build the project
It is an ant based project, not en eclipse project. You can call ant from eclipse, but there is no specic eclipse files (.project and .classpath) so that it can run with gwt eclipse plugin without configuring it yourself.

Getting gwt hibernate example code to work with eclipse

I am starting out with GWT and hibernate. I'm going through the tutorial at https://developers.google.com/web-toolkit/articles/using_gwt_with_hibernate.
I downloaded the sample code provided with the tutorial (http://google-web-toolkit.googlecode.com/files/gwt_hibernate_base.zip). This is a simple music store where you can add an account and records. I am able to run this and successfully add accounts and records to the database by doing the following commands:
(in the data directory) java -cp ../lib/hsqldb.jar org.hsqldb.Server
ant build hosted
Here is the build.xml file used to build this:
<?xml version="1.0" encoding="utf-8" ?>
<project name="Guestbook" default="build" basedir=".">
<!-- Define gwt.home, gwt.dev.jar, appengine.sdk.home -->
<property file="build.properties"/>
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes"/>
<pathelement location="${gwt.home}/gwt-user.jar"/>
<!-- Add any additional non-server libs (such as JUnit) -->
<fileset dir="war/WEB-INF/lib">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="libs" description="Copy libs to WEB-INF/lib">
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib" file="${gwt.home}/gwt-servlet.jar" />
<!-- Add any additional server libs that need to be copied -->
<copy todir="war/WEB-INF/lib" flatten="true">
<fileset dir="lib/">
<include name="**/*.jar"/>
</fileset>
</copy>
</target>
<target name="javac" depends="libs" description="Compile java source">
<mkdir dir="war/WEB-INF/classes"/>
<javac srcdir="src" includes="**" encoding="utf-8"
destdir="war/WEB-INF/classes"
source="1.5" target="1.5" nowarn="true"
debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path"/>
</javac>
</target>
<!-- can add additional arguments like -logLevel INFO or -style PRETTY -->
<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"/>
<pathelement location="${gwt.home}/${gwt.dev.jar}"/>
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<arg value="com.google.musicstore.MusicStore"/>
</java>
</target>
<target name="hosted" depends="javac" description="Run hosted mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="${gwt.home}/${gwt.dev.jar}"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="-startupUrl"/>
<arg value="MusicStore.html"/>
<arg value="com.google.musicstore.MusicStore"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
</java>
</target>
<target name="build" depends="gwtc" description="Build this project" />
<target name="clean" description="Cleans this project">
<delete dir="war/WEB-INF/classes" failonerror="false" />
<delete dir="war/musicstore" failonerror="false" />
</target>
Now I would like to get this simple example working in eclipse. I created a project called MusicStore using the gwt eclipse plugin. I then copied over the tutorial files without changing them. I can't post an image but here is a link to my eclipse project structure:
http://oi50.tinypic.com/t6rn2w.jpg
Again, I start by running
(in the data directory) java -cp ../lib/hsqldb.jar org.hsqldb.Server
Then I try to run my project in eclipse but hibernate doesn't work. When I try to add an account in the UI it alerts "Failed to save account" and I get the error java.lang.NoClassDefFoundError: org/hibernate/Session.
Please let me know how I should go about getting the sample code working with eclipse. I think that many users new to hibernate will also want to do this.
Thanks!
Basically eclipse cannot find your hibernate libraries. That is because your build.xml is for building a war file. Eclipse doesn't read it so it doesn't have any of your build information in there.
A quick solution to this is to just go to the "Build Path" properties in Eclipse and make sure your /lib directory is included in the "Libraries" tab. Then eclipse will know where you are keeping your libraries.
A better solution would be to use something like Maven. Then the Maven Plugin for Eclipse will automatically look at the Maven build file and configure the Eclipse project so that it can detect where the libraries are held etc...

Create GWT-compile rule for Ant build.xml

I'm trying to make an Eclipse-compilable GWT project also compilable on the command line (via Ant).
Eclipse provides functionality to export a build.xml; this works fine for compiling the classes, but since GWT's special stuff is all provided via a plugin, these rules are not included.
Google provides a tool for creating build.xml files for new projects. I've incorporated the rules generated by this into the Eclipse-exported file.
Compiling (the part provided by Eclipse) is successful.
Here is the compile-things-to-javascript task:
<target name="gwtc" depends="build" description="GWT compile to JavaScript (production mode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="war/WEB-INF/classes"/>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="/Applications/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0/validation-api-1.0.0.GA.jar" />
<pathelement location="/Applications/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0/validation-api-1.0.0.GA-sources.jar" />
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<!--<arg line="-style PRETTY"/>-->
<arg line="-war"/>
<arg value="war"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg line="${gwt.args}"/>
<arg value="edu.calpoly.csc.scheduler"/>
</java>
</target>
The .gwt.xml file looks like so:
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='gwtview'>
<!-- 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.clean.Clean'/>
<!-- <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='edu.calpoly.csc.scheduler.view.client.GWTView'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
<source path='view'/>
</module>
When trying to run the task, I get this error:
gwtc:
[java] Compiling module edu.calpoly.csc.scheduler
[java] Finding entry point classes
[java] [ERROR] Unable to find type 'edu.calpoly.csc.scheduler.view.client.GWTView'
[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
Which seems strange to me, since the class is very much there:
[$]> ls war/WEB-INF/classes/edu/calpoly/csc/scheduler/view/client
GWTView$1.class GWTView$1MyHandler.class GreetingService.class
GWTView$1MyHandler$1.class GWTView.class GreetingServiceAsync.class
Halp?
Are you sure you have sources of your GWT app on classpath? GWT is compiling java sources to js, not *.class files.
Make sure that you have that library/jar and any other SOURCE needed available on the classpath you pass to the GWT Compiler, as it will need to be able to find the Java source inside GWT libs to be able to compile them, unlike the Javac compiler than can compile against libraries using just the provided .class files.
Here is my ant gwtc compile macro. (removed leading <to avoid formatting problems...)
macrodef name="gwtCompileApplication" >
<attribute name="app" />
<attribute name="extraArgs" default="" />
<attribute name="gwtcExtras" default="" />
<sequential>
<java classpathref="gwtCompile.classpath" classname="com.google.gwt.dev.Compiler" fork="true" failonerror="true">
<jvmarg value="-Xmx512M" />
<arg value="-strict" />
<!-- Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
<arg value="-logLevel" />
<arg value="DEBUG" />
-->
<!-- request detailed, non-obfuscated JS output
<arg value="-style" />
<arg value="DETAILED" />
-->
<arg value="-localWorkers" />
<arg value="4" />
<arg value="-war" />
<arg value="${war.dir}" />
<arg value="-deploy" />
<arg value="deploy" />
<!-- These two lines have been removed as otherwise it won't work on Mac OS X
<arg value="#{extraArgs}" />
<arg value="#{gwtcExtras}" />
-->
<!-- This can be used to see more details about warnings, but they will be converted to errors and build will fail
<arg value="-strict" />
-->
<arg value="-logLevel" />
<arg value="INFO" />
<arg value="#{app}" />
</java>
</sequential>
</macrodef>
This can be invoked from any target thus:
A target to compile a specific module of mine called 'Admin" where the file Admin.gwt.xml file is inside .ta.Admin. I have a debug and production build type and a .gwt.xml different for each one to speed up compiling for debug (fewer user agents and languages = fewer permutations)
target name="gwtcAdmin" depends="compile, buildtype" description="GWT Compile Admin" >
<gwtCompileApplication app="com.bcntouch.ta.Admin.${build_type}_Admin" extraArgs="${gwtcArgs}" gwtcExtras="${gwtcExtras}"/>
</target>
But the key part if the GWT compile class path I use. Here is the target where I setup my paths:
target name="gwtPath">
<path id="gwt.classpath">
<pathelement location="${gwt.sdk.dir}/gwt-user.jar" />
<pathelement location="${gwt.sdk.dir}/gwt-servlet.jar" />
</path>
<!-- For GWT compile we need a path with source AND the GWT Compiler classes -->
<path id="gwtCompile.classpath">
<path refid="source.classpath" />
<!-- This is put after source, so GWT Compiler it doesn't pick up out of date versions of old css and uibinder
files in classes generated by Eclipse/GWT Plugin -->
<path refid="classpath" />
<path refid="tool.classpath" />
</path>
</target>

Using SVNAnt in eclipse Build Failed (Could not load definitions from resource)

I want to use SVNAnt in eclipse.
But when I run my script, I have this message :
Buildfile: X:\XXX\bin\ant\axis_bujava.xml
[typedef] Could not load definitions from resource org/tigris/subversion/svnant/svnantlib.xml. It could not be found.
testSVNAnt:
BUILD FAILED
X:\XXX\bin\ant\axis_bujava.xml:11: Problem: failed to create task or type svn
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Here is the Ant build file :
<?xml version="1.0"?>
<project default="testSVNAnt" basedir=".">
<path id="path.svnant">
<pathelement location="${basedir}/svnant.jar"/>
<pathelement location="${basedir}/svnClientAdapter.jar"/>
</path>
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="path.svnant" />
<target name="testSVNAnt">
<svn username="username" password="pass">
<checkout url="svn://svnurl" destPath="localpath" revision="HEAD"/>
</svn>
<echo message= "Subversion repository url: ${repository.url}" />
</target>
</project>
The JAR files are of course in basedir. I can't find similar problem nor any solutions.
It finaly work using SvnAnt 1.3.1.
The checkout work fine using this code :
<?xml version="1.0"?>
<project default="main" basedir=".">
<path id="path.svnant">
<pathelement location="${basedir}/svnant.jar" />
<pathelement location="${basedir}/svnClientAdapter.jar" />
<pathelement location="${basedir}/svnjavahl.jar" />
</path>
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="path.svnant" />
<target name="main">
<svn>
<checkout url="svn://xxx" destPath="X:/XXX" revision="HEAD" />
</svn>
</target>
</project>
Thanks for help.
You have to use
<taskdef />
instead of <typedef/>
Everything else looks fine.
had the same problem.. replacing the value of "resource" from "org/tigris/subversion/svnant/svnantlib.xml" TO "svntask.properties" did it for me.
sample below: (svn_1.0.0; eclipse juno)
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="D:/.../ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<path id="path.svnant">
<pathelement location="D:/.../lib/svnant.jar" />
<pathelement location="D:/.../lib/svnClientAdapter.jar" />
<pathelement location="D:/.../lib/svnjavahl.jar" />
</path>
<typedef **resource="svntask.properties"** classpathref="path.svnant"/>
<target name="ifAvailable">
<available classpathref="path.svnant" **resource="svntask.properties"**
property="temp"/>
<echo message="SVNAnt is available = ${temp}"></echo>
</target>
OUTPUT>>>>>
Buildfile: D:\...\build.xml
ifAvailable:
[echo] SVNAnt is available = true
BUILD SUCCESSFUL
Total time: 306 milliseconds
Replace
<taskdef resource="org/tigris/subversion/svnant/svnantlib.xml" />
with
<taskdef resource="svntask.properties"/>
The svntask.properties are present in the svnant.jar

GWT hosted mode not working with Spring + Eclipse + GWT Eclipse plugin

I've been trying to get GWT working with Spring for a while now. Is there anyone who is using official Eclipse GWT plugin with Spring, and who has managed to get hosted mode working with that combination?
I'm using GWTController to initialize GWT through dispatcher-servlet.xml. Since my WEB-INF is not in war, but in WebContent folder, I use "-war WebContent" switch when compiling Java code to .js.
As for hosted mode... if I try to run it through IDE (Run as Web Application) I get "Launch failed - Could not find any host pages in project MyProject." I tried running it with Ant task which goes something like this:
<condition property="XstartOnFirstThread" value="-XstartOnFirstThread">
<os family="mac"/>
</condition>
<condition property="XstartOnFirstThread" value="">
<not><os family="mac"/></not>
</condition>
<target name="hosted" depends="" description="Run hosted mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.HostedMode">
<classpath>
<pathelement location="src" />
<path refid="my-client-classpath" />
</classpath>
<jvmarg value="-Xmx256M" />
<jvmarg line="${XstartOnFirstThread}" />
<arg value="-startupUrl" />
<arg value="MyPage.html" />
<arg value="my.gwt.client.Whatever" />
</java>
</target>
This results in hosted mode starting, but I get 404 instead of my web page...
EDIT: When I go to hosted mode, I see folder with compiled Javascript code but nothing else. So my question is basically has someone got a good tutorial or a setup he can share? There is a lot of half-baked info on the Net, but I wasn't able to make any of it work.
EDIT 2: Here's my .gwt.xml file, it's pretty basic:
<?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='whatever'>
<!-- 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='my.gwt.client.Whatever' />
<!-- Lokalizacije -->
<extend-property name="locale" values="hr" />
</module>
We used this tutorial to get it working for us, hope it helps