GWT by hand (no xml configuration, no ant, no running gwt-dev.jar)

63 views
Skip to first unread message

Harry

unread,
Feb 21, 2012, 11:04:01 PM2/21/12
to Google Web Toolkit
I'm interested in using GWT, but not with any of the utility programs
(except the compiler) it comes with, nor an XML configuration. That
is,

1) I'd like to have a 'public static void main(String[] args)' method
in a class which sets up a web server, configures the servlet etc.

2) I want to be able to run "Development Mode" by having my main
method called, and calling into whatever classes I need to to get it
going. I don't want to use gwt-dev.jar or any eclipse start magic.
(And of course, I don't want any method I'm calling to take an xml
file - and no lets not be smart and build one on the fly).

3) To run in "Production Mode" I'd like to call invoke the compiler
directly (no ant) to generate whatever files I need. Then actually
start my program and have it add any servlets it needs to Jetty's
context (lets for the sake of the example assume we're using Jetty),
and add handlers to serve the static content.

Everything I've need seems to use ant or some gwt programs to create
the directory structure or some eclipse magic project. I would like to
do this all by hand, and therefore I need to know *what* to do, and
I'd like to *know* this without having to having to look at the gwt
source code to figure out what it does when it's main() is invoked.

JoseM

unread,
Feb 22, 2012, 10:28:55 AM2/22/12
to google-we...@googlegroups.com
I can't help you since I myself wouldn't know how to do what you are asking but why?!? I'm sure they are using what they currently have because there are a lot of different complicated steps to do their magic. Does it not meet the need that you currently have?

Jens

unread,
Feb 22, 2012, 11:25:45 AM2/22/12
to google-we...@googlegroups.com
1) Just use any sort of embedded web server like jetty and let it serve the war folder of your GWT project.

2 + 3.) You will definitely need gwt-dev.jar & gwt-user.jar in your classpath and then you can use:
   - com.google.gwt.dev.DevMode to run GWT's DevMode
   - com.google.gwt.dev.Compiler to compile your Java files to JavaScript.
Both classes have a main() method so you can directly execute them from command line as long as your classpath is correct and you provide the needed parameters.

-- J.

Harry

unread,
Feb 23, 2012, 9:26:34 PM2/23/12
to Google Web Toolkit
Jens, thanks for your reply.

For 1) I already have jetty and I've added the my servlet to Jetty's
context.

For 2+3) I'm sure I'll need gwt-dev and user in my class path. But I'd
like to do something that has a little more finesse than invoking the
main on their class. I'd really like to instantiate the classes I need
(or better yet, there is some factory I can instantiate in their jar).
But even if I call main, I'm pretty sure I need to have some XML
config file.

I just don't want to have an XML configuration, when I could tell GWT
about it programatically.

Thomas Broyer

unread,
Feb 24, 2012, 4:07:25 AM2/24/12
to google-we...@googlegroups.com
I honestly don't understand why you don't want to use *.gwt.xml files but well, you can create a module programmatically using ModuleDefLoader.createSyntheticModule (this is used in JUnitShell to create a module that inherits both your module –the one whose name you return from your GWTTestCase#getModuleName()– and com.google.gwt.junit.JUnit).
As for calling the DevMode and/or Compiler (and again, I don't understand why you don't want to simply call them from the command-line, and use -noserver for the DevMode and use your own Jetty server), *do* look into their main(): you have to create a CompilerOptions instance (or similar for DevMode) that you pass as constructor argument to a Compiler instance, and then call its run() method; and similarly for the DevMode.
Currently, the Compiler's main() uses a CompileTask and CompileTaskRunner, but they don't seem to bring much value; you'd better use them though to be future-proof.
Reply all
Reply to author
Forward
0 new messages