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

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

Related

GWT Error: There is '1' error in 'gwt-module.dtd'

I am learning GWT and was trying to run this tutorial by Vogella
Using the Eclipse GWT plugin 3.0 on Windows 10 and JDK 11
I get this error on the first line Error: There is '1' error in 'gwt-module.dtd'.
/de.vogella.gwt.helloworld/src/de/vogella/gwt/helloworld/De_vogella_gwt_helloworld.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
When updating your version of GWT, you should also update this DTD reference,
so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.8.1//EN"
"http://gwtproject.org/doctype/2.8.1/gwt-module.dtd">
<module rename-to='de_vogella_gwt_helloworld'>
<!-- 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='de.vogella.gwt.helloworld.client.De_vogella_gwt_helloworld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
<!-- allow Super Dev Mode -->
<add-linker name="xsiframe"/>
</module>
I get the same error even from the official GWT tutorial http://www.gwtproject.org/doc/latest/tutorial/index.html
From this post, I found that the dtd generated is wrong.
"http://gwtproject.org/doctype/2.8.1/gwt-module.dtd"
I corrected it to
"http://www.gwtproject.org/doctype/2.8.1/gwt-module.dtd"
and the error went away!

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 java objects from another Maven module in GWT on the client side

i have two maven projects, project A contents some serializable model objects and project B is the GWT project. Now i want to use some Objects from project A for RPC calls between the client and the server in project B.
so here is what i have done yet:
GWT project B xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.4.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.4.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='Index'>
<inherits name='com.google.gwt.user.User' />
<inherits name='com.projectA.Models' />
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<entry-point class='com.projectB.client.Index' />
<source path='client' />
<source path='shared' />
</module>
Java Object project A xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.4.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.4.0/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.google.gwt.user.User"/>
<source path="./" />
</module>
I still get "No source code is available for type com.projectA.Object; did you forget to inherit a required module?" message =(
(POM dependency is set!)
i figured out i need to add this to the maven gwt plugin configuration in the POM of project B:
<configuration>
<compileSourcesArtifacts>
<compileSourcesArtifact>com.projectA:Models</compileSourcesArtifact>
</compileSourcesArtifacts>
</configuration>
this tells the Maven GWT plugin to copy the sources to the web directory... Additionally you need an GWT xml file in the project B package with the following:
<module>
<inherits name='com.google.gwt.user.User' />
<source path='' />
</module>
That tells the GWT compiler to include the source of that module..
DONE
Just to be clear-
projectA structure: com.projectA.ProjectA.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.4.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.4.0/distro-source/core/src/gwt-module.dtd">
<module rename-to="first-project">
<inherits name="com.google.gwt.user.User"/>
<source path="./" />
</module>
Then projectB structure will be: com.projectB.ProjectB.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.4.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.4.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='Index'>
<inherits name='com.google.gwt.user.User' />
<inherits name='com.projectA.first-project' />
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<entry-point class='com.projectB.client.Index' />
<source path='client' />
<source path='shared' />
</module>
I add rename to projectA gwt.xml. Please review code. This sample should work. If your pom has correct dependency.

Folder with jars in project

When I work on small desktop projects I used to create lib folder in my project's root where I keep all project's jar dependencies. Then I use Configure Build Path -> Libraries -> Add JARs... to manually add all jars from this folder to buildpath/classpath. And because Add JARs... (unlike Add external JARs) uses relative paths, the project is portable, what is important for me.
The problem is that each time I add or remove a jar from my lib folder I need to manually add/remove this jar in project buildpath settings (and of course I often forget to do so).
Is there a way to just inform Eclipse that "This is a folder where I keep all of my jars. Please, add all the jars from there automatically to buildpath/classpath"? I tried to treat this folder as a class folder (Add class folder...) but it doesn't work that way :(.
P.S. I know about Maven and Eclipse-Maven integration but I want to keep my small project's simple (Maven integration is sometimes frustrating so I prefer to avoid it in these projects), so please don't suggest this in answer. Also as I mentioned, these are desktop projects, so there is no WEB-INF/lib folder in my project that is usually automatically handled by Java EE plugins.
you can try with a classpath container, take a look here for an example .
Take a look also at the Apache IvyDE classpath container .
However adding a new library to the classpath is simple and quick as :
Right click on it ---> Build Path ---> Add To Build Path
EDIT
This lightweight plugin should do exactly what you want !
I am not too sure, but can't you have wildcards in your classpath? That way you could just edit your .classpath file for that Eclipse project and use * within a particular folder... I have not tried, i'm in a rush but that's my idea... don't know if works
EDIT here is something that you could find useful:
How to use a wildcard in the classpath to add multiple jars?
Basically, just edit your .classpath file, which is where Eclipse stores the classpath settings for a project
I think the best is to use Gradle. This does not have the frustration of Maven with Eclipse. If you use STS it comes with Gradle pre-bundled.
See the link
So yeah I did this before:
Use Apache Ant and specify an ant configuration that suits your build path and eclipse should be able to use it with the use from existing ant build option.
Here is an example ant file you might have:
<?xml version="1.0"?>
<project name="Demo Project" basedir="." default="package">
<!-- ================================================================= -->
<!-- C O N F I G U R A T I O N -->
<!-- ================================================================= -->
<!--
Access the environment properties
-->
<property environment="env" />
<!--
TODO: Access the environment properties with a prefix of "env".
-->
<!--
Additional 3rd-party tools
-->
<property name="ant.home" value="${env.ANT_HOME}"/>
<property name="junit.home" value="${env.JUNIT_HOME}"/>
<property name="jmock.home" value="${env.JMOCK_HOME}"/>
<!--
Project folders
-->
<property name="project.home" value="${basedir}" />
<property name="bin.dir" value="${project.home}/bin" />
<property name="dist.dir" value="${project.home}/dist" />
<property name="dist.file" value="${dist.dir}/lab03.jar" />
<property name="col.file" value="${dist.dir}/lab03-col.jar" />
<property name="src.dir" value="${project.home}/src" />
<property name="lib.dir" value="${project.home}/lib" />
<!--
TODO: Define the classpath to be used during compilation. This should
consist of all of the JAR files in the ${lib.dir} folder.
-->
<path id="project.class.path">
<path location="${dist.file}" />
<path location="${bin.dir}" />
<fileset dir="${junit.home}">
<include name="junit-4.7.jar"/>
</fileset>
<fileset dir="${jmock.home}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${ant.home}/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!--
TODO: Define the classpath to be used during execution. This should
consist of all of the JAR files in the ${lib.dir} folder as well as
${dist.file}.
-->
<path id="execution.class.path">
<path location="${bin.dir}" />
<path location="${bin.dir}/MyPath1/MyPath" />
<path location="${bin.dir}/MyPath1/MyPath/impl" />
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- ================================================================= -->
<!-- C L E A N -->
<!-- ================================================================= -->
<target name="clean"
description="Clean all build products">
<delete dir="${bin.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- ================================================================= -->
<!-- C O M P I L E -->
<!-- ================================================================= -->
<target name="compile"
depends="clean,init"
description="Compiles the application code">
<!--
TODO: Add the javac task. It should compile everything in ${src.dir}
and place the output in ${bin.dir}. The classpath should refer to the
"project.class.path" defined above.
-->
<javac srcdir="${src.dir}"
destdir="${bin.dir}">
<classpath refid="project.class.path" />
</javac>
</target>
<!-- ================================================================= -->
<!-- E N V -->
<!-- ================================================================= -->
<target name="env"
description="Displays information about the build">
<echo message="src.dir..........${src.dir}" />
<echo message="lib.dir..........${lib.dir}" />
<echo message="bin.dir..........${bin.dir}" />
<echo message="dist.dir.........${dist.dir}" />
<echo message="dist.file........${dist.file}" />
<echo message="col.file.........${col.file}" />
<echo message="reports.dir......${reports.dir}" />
</target>
<!-- ================================================================= -->
<!-- I N I T -->
<!-- ================================================================= -->
<target name="init"
depends="env"
description="Initializes the environment">
<mkdir dir="${bin.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- ================================================================= -->
<!-- P A C K A G E -->
<!-- ================================================================= -->
<target name="package"
depends="compile"
description="Creates the application distribution file">
<!--
TODO: Create a JAR file. The target JAR should be ${dist.file} and it
should contain everything from ${bin.dir}.
-->
<jar destfile="${dist.file}"
basedir="${bin.dir}"
excludes="**/*Test*.class"
/>
</target>
<!-- ================================================================= -->
<!-- P A C K A G E - C O L -->
<!-- ================================================================= -->
<target name="package-col"
depends="compile"
description="Creates the file to be submitted to COL.">
<jar destfile="${col.file}">
<fileset dir="${project.home}"
includes="src/**/*.java" />
<fileset dir="${project.home}"
includes="lib/**/*.jar" />
<fileset dir="${project.home}"
includes="build.xml" />
</jar>
</target>
<!-- ================================================================= -->
<!-- R U N -->
<!-- ================================================================= -->
<target name="run"
depends="package"
description="Executes the test file">
<java classname="MyPath1.MyPath.FileScanner">
<classpath refid="execution.class.path" />
<arg value="file:///" />
</java>
</target>
</project>
AND Here is a link with someone with a similair problem using ant to solve his classpath problems.
Ant is portable so it can actually be set up anywhere and you can also use global variables to keep all systems consistent or just use relative paths. And there is also an eclipse ant plugin
just try including
<classpathentry kind="lib" path="lib/spring/4.2.1" including="*.jar"/>

How to debug GWT using Ant

I know that the job would be simpler if I use Google Plugin for Eclipse.
However, in my situation, I heavily adapted Maven and thus, the plugin cannot suit me. (In fact, it gave me the whole week of headache).
Rather, I relied on a ant script that I learned from http://code.google.com/webtoolkit/doc/latest/tutorial/appengine.html
The document was very clear; I follow the article and successfully invoked DevMode using ant devmode. However, the document didn't tell me about debugging GWT (like Google Plugin for Eclipse can do).
Basically, I want to add some parameter to an ant task that expose a debug port (something like (com.google.gwt.dev.DevMode at localhost:58807)) so that I can connect my eclipse to.
How can I do that?
I have successfully done this with the following ant task (the build.xml file sits in the root of the GWT project):
<target name="devmode" description="Run development mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode">
<classpath>
<pathelement path="${project.class.path}" />
<pathelement path="${project.src.path}" />
</classpath>
<jvmarg value="-Xmx512M" />
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" />
<arg value="-startupUrl" />
<arg value="http://localhost/whatever" />
<arg value="-noserver" />
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg value="-war" />
<arg value="." />
<arg value="-logLevel" />
<arg value="DEBUG" />
<arg value="com.example.Application" />
</java>
</target>
Then I created a "Remote Java Application" launcher that connects to that debug session with "Connection Type" set to "Standard", "Host" set to the hostname of the machine and "Port" set to 8000.
Haven't tested it in a while though but it did work before :)