Using Guava with GWT - gwt

Could someone tell me what I need to do to enable Guava support in GWT.
I have downloaded Guava R07 and in there there are the following two files:
guava-r07.jar
guava-r07-gwt.jar
I have a few questions regarding this:
Where do these files go? I am guessing that the standard Jar is made available to my IDE for coding, and that both are made available to the GWT compiler for building the JavaScript?
Do I need to add all the .gwt.xml files from the -gwt.jar into my project's main gwt.xml file or only the portions I need?
There are other Jars on the trunk of the Guava&GWT project (ie not in the download, such as one for jsr305) which I think I may need, but I'm not sure.
Sorry, normally I don't have trouble with this kind of thing, but I can't quite work out what goes where.
FYI I'm using GWT 1.6 for the time being, but am hoping to move to 2 soon. If Guava isn't compatible with 1.6 that is not a problem.
Update
I have the following files in a folder called gwtlib:
guava-r07-gwt.jar
guava-r07.jar
jsr305-1.3.9.jar
And my Ant script does the following:
<path id="project.class.path">
<fileset dir="gwtlibs" includes="guava-r07.jar"/>
<fileset dir="gwtlibs" includes="guava-r07-gwt.jar"/>
<fileset dir="gwtlibs" includes="jsr305-1.3.9.jar"/>
<pathelement location="${gwt.sdk}/gwt-user.jar"/>
<fileset dir="${gwt.sdk}" includes="gwt-dev*.jar"/>
</path>
<target name="gwtc">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="app"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="-localWorkers"/>
<arg value="2"/>
<arg value="-war"/>
<arg value="gwt-public"/>
<arg value="Main"/>
</java>
</target>
Running the above command, I get the following errors:
Errors in 'jar:file:///project/gwtlibs/guava-r07-gwt.jar!/com/google/common/collect/Constraints.java'
Line 254: The method subList(int, int) is undefined for the type List
Without the jsr jar on the classpath, I get the following errors:
The import javax.annotation cannot be resolved
Nullable cannot be resolved to a type
Thanks
Rich

Add these jars to your classpath. If you're using IDE, add them to your Build Path by right-clicking "Referenced Libraries" in your Package Exporer, select "Configure Build Path" and add them as external JARs.
You only need to inherit the modules you plan on using in your .gwt.xml file. For example, if you only use the common.collect package, just add <inherits name="com.google.common.collect.Collect" />
You probably don't need jsr305.jar, but if you do, just add it the same way as you added the other jars.
Guava should work just fine with GWT 1.6, if it doesn't then it's probably a bug.

Guava isn't compatible with GWT 1.6. List.subList, in particular, is added to GWT in GWT 2. The earliest version that we fully supported is GWT 2.0.4

Related

Getting an error "Could not load definitions from resource net/sf/antcontrib/antcontrib.properties. It could not be found."

I am getting an error Could not load definitions from resource net/sf/antcontrib/antcontrib.properties. It could not be found. when I am trying to ant build on eclipse. So I downloaded ant-contrib-0.6.jar and kept it in my /lib location of apache ant, but it still does not resolve my issue. I have also tried by specifying the /lib location in my CLASSPATH system variable. How can I get around this error?
You can provide full path to the ant-contrib JAR explicitly using "classpath" element:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${path-to-ant-contrib}/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
EDIT: Link contributed by Djacomo:
http://ant-contrib.sourceforge.net/
One important thing missing from this StackOverflow page is that setting the correct ANT_HOME env var is absolutely vital and important, without this setting ant keeps telling the same error, regardless of where you copy the ant-contrib-1.0b3.jar on your file systems. This missing thing has costed me a few hours. =)
However I receive this error without eclipse, in the pure ant.
I fixed that this way:
Add the JAR to the Ant runtime classpath entries.
Window>Preferences>Ant>Runtime>Classpath
Add the JAR to either Ant Home Entries or Global Entries.
It would appear that you haven't installed the ant contrib jar into the correct lib directory. This can be difficult to do if you have several installations of ANT.
My suggestion is to install your ANT plugins into the "$HOME/.ant/lib" directory. You could go one step further and automate the process as follows:
<project name="ant-contrib-tasks" default="all">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<target name="bootstrap">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ant-contrib.jar" src="http://search.maven.org/remotecontent?filepath=ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
</target>
<target name="all">
<for param="file">
<fileset dir="." includes="*.txt"/>
<sequential>
<echo message="Found file #{file}"/>
</sequential>
</for>
</target>
</project>
Use the below mentioned code in your build xml:
<path id="ant.classpath">
<pathelement location="${ant.jarPath}/ant.jar" />
<pathelement location="${ant.jarPath}/ant-contrib-0.3.jar" />
</path>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath refid="ant.classpath" />
</taskdef>
And in your build property file:
ant.jarPath=D:/antjars
And place ant.jar and ant-contrib-0.3.jar in directory:D:/antjars
Check you have read permissions for the ant-contrib jar file.
In our case after copying the file with another user it did not, giving the same error message.

Ant, Groovy, GWT Invoking GWT compile with AntBuilder

Hi I'm working my way through creating a groovy script to automate building and packaging a gwt application.
AntBuilder is bundled as part of Groovy and I really like the concept. It really does help the readability of the resulting script.
However I'm having some problems getting my script to invoke the GWT compiler. The code is as follows:
ant.sequential{
path( id:"gwt.path" , location:"src", { fileset (dir:"${GWT_HOME}", includes:"gwt-dev.jar" ) } )
ant.java ( fork:true, maxmemory:"256M", classpathref:"gwt.path", classname:"com.google.gwt.dev.Compiler"
, { classpath { pathelement location:"src" }
classpath { pathelement location:"${GWT_HOME}/gwt-user.jar" }
classpath { pathelement location:"${WEB_INF}/classes" }
arg (value:"-war")
arg (value:"bin/www")
arg (value:"com/xxx/xxx/xx/xxx/xxx/GWT_DuplicateFinder")
}
)
}
As far as I can tell I've converted the equivalent ant scripting correctly (pasted from a previous build.xml file used on another gwt project.
<target name="web" depends="compile" description="GWT Web Compilation">
<mkdir dir="${gwt.web.out.dir}"/>
<java fork="true" maxmemory="256M" classpathref="gwt.path" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<!-- Note the reference to the compiled java classes -->
<pathelement location="war/WEB-INF/classes"/>
</classpath>
<arg value="-war"/>
<arg value="bin/www"/>
<arg value="com/xxx/xxx/xx/xxx/xxx/GWT_DuplicateFinder"/>
</java>
</target>
The error I'm getting is :
[java] [ERROR] Unable to find 'com/xxx/xxx/xx/xxx/xxx/GWT_DuplicateFinder.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
Could anyone tell me where I'm going wrong.
Since the GWT compiler can not see the GWT_DuplicateFinder.gwt.xml file, there must be something wrong with the paths. You do have the src folder in the path, that is fine. So maybe the base directory or working directory is not correct (or not set at all).

How can someone run RequestFactory's ValidationTool from ant?

I use:
<java failonerror="true" classname="com.google.web.bindery.requestfactory.apt.ValidationTool">
<arg path="${path.to.ouput.jar}" />
<arg value="com.my.RequestFactory" />
<classpath>
<path refid="my_classpath" />
</classpath>
</java>
my_classpath has all requestfactory-client.jar, requestfactory-server.jar, requestfactory-apt.jar + my source & the jar produced from it in the path (that's confirmed with just printing it), but I still get:
[java] error: Unable to find RequestFactory built-in type. Is requestfactory-[client|server].jar on the classpath?
What could be wrong here?
For me, this works only, if I specify <javac fork="true" ...
From the official ant documentation on the java task:
If odd things go wrong when you run this task, set fork="true" to use a new JVM.
Without any deep investigation, I would say it's most likely a classloader problem.

script to execute the eclipse PDE Tools > Build site

i want to write a script to do the Build site of plugin Update site site.xml?
i could not find a way to do this?
i found very easy to build a plugin feature. I can automatically creat the ant file build.xml via eclipse but i could not find the same for the update site.xml
thank you all
stefania
Are you trying to build an Eclipse plugin from Ant? You want to use the Ant4Eclipse external add-on for Ant. It lets you build the run-configurations you've made in Eclipse (right click>run as>...) from your .project file. You can download it here and there is a tutorial here.
I attempted to do what you're asking at a previous job without using Ant4Eclipse, I don't remember how I got it working, but I do remember it being extremely difficult.
Edit: you can build an Eclipse update site from the command line, which can be run from Ant. There is some [possibly out of date] documentation here, but I found you a sample from an Apache projects build.xml:
<target name="build-site" depends="init">
<copy todir="target/eclipse-update-site/web" preservelastmodified="true">
<fileset dir="web"/>
</copy>
<copy todir="target/eclipse-update-site" file="index.html" preservelastmodified="true"/>
<copy todir="target/eclipse-update-site" file="site.xml" preservelastmodified="true"/>
<!-- copy all the features to the target -->
<copy todir="target/eclipse-update-site/features" preservelastmodified="true" >
<fileset dir="features"/>
</copy>
<!-- see http://wiki.eclipse.org/Update_Site_Optimization -->
<java jar="${eclipse.home}/plugins/org.eclipse.equinox.launcher.jar" fork="true" failonerror="true"
maxmemory="256m">
<arg line="-application org.eclipse.update.core.siteOptimizer"/>
<arg line="-digestBuilder -digestOutputDir=target/eclipse-update-site"/>
<arg line="-siteXML=target/eclipse-update-site/site.xml"/>
</java>
</target>

org/apache/commons/codec/DecoderException when integrating Ant-Contrib into Eclipse

I've tried to integrate Ant-Contrib 1.0b3 into Eclipse by adding the ant-contrib-1.0b3.jar and the appendant jar-files from the libs-directory to the "Global Entries"-section of the Ant-Runtime-preferences page in Eclipse.
For tasks that don't need the libs, such as propertyregex, this works fine.
But when I try to use the postMethod task I get the following error:
java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
Any suggestions on what to do to resolve this?
It looks like your rig doesn't include the Apache Commons Codec which must be a dependency of ant-contrib.
According to the dependencies here you might also need commons-logging, but you've probably already got that.
It's much cleaner to specify classpath when you define 3rd-party tasks in your build file.
Provide either individual jars or add a <fileset> of dependent jars to classpath, e.g.
<taskdef
resource="net/sf/antcontrib/antlib.xml"
uri="http://ant-contrib.sourceforge.net"
>
<classpath>
<pathelement location="${ant-contrib.jar}"/>
<fileset dir="${ant-contrib-dependency.lib}">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
You can define default ant-contrib.jar and ant-contrib-dependency.lib properties in this build file, and provide project specific overrides in ant build tool VM arguments. This means you don't have to copy these files into various directories on your system.