Setting the java classpath (for super dev mode)

Riley Lark picture Riley Lark · Jun 29, 2012 · Viewed 13.8k times · Source

I'm trying to run a jar, gwt-codeserver.jar, in OSX.7, with the command

java -cp ".:/sdk/gwt-2.5.0.rc1/gwt-dev.jar" -jar /sdk/gwt-2.5.0.rc1/gwt-codeserver.jar com.activegrade.TeacherView

The command fails with:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gwt/core/ext/TreeLogger
Caused by: java.lang.ClassNotFoundException: com.google.gwt.core.ext.TreeLogger
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    ...

But gwt-dev.jar contains the definition for com.google.gwt.core.ext.TreeLogger, so I've concluded that I'm not properly setting the classpath here.

Am I setting the classpath correctly? The jar file is definitely the right jar and it's definitely at that location. How can I diagnose this further?

Answer

Ezward picture Ezward · Jul 1, 2012

I've got the CodeServer running as an external tool in Eclipse (caveat - you still have to server your html file somehow, which I have not yet done, but this does seem to get the codeserver running). To setup the CodeServer as an external tool in Eclipse,

0) Remember that you should also update your module.gwt.xml file to allow Super Dev Mode book marklets and to enable source maps for debugging. Add these likes to your module.gwt.xml file.

<!-- enable the SuperDevMode book marklets  -->
<add-linker name="xsiframe"/>
<set-configuration-property name="devModeRedirectEnabled" value="true"/>

<!--  enable source maps -->
<set-property name="compiler.useSourceMaps" value="true" />

1) Open the External Tools/External Tools Configurations dialog; this is under the top level 'Run' menu in Windows.

2) Create a new configuration by selecting 'Program' in the list on the left, then press the 'New' button (it looks like a document). Name your configuration in the dialog.

3) The path to your java.exe file goes in the 'Location:' box. You can use the 'Browse File System' button to locate it if you don't know the path.

4) I left working directory blank. I'm not sure if this matters; it seems to work without it. Does anyone out there know for sure if this should be set?

5) The bulk of the work in in the "Arguments:" box. You will provide an argument for the class path which will include the path to gwt-dev.jar, gwt.user.jar, gwt-codeserver.jar and to your source directory. Then you will provide a -jar and argument to the gwt-codeserver.jar and the CodeServer class to run, then you will provide the arguments to CodeServer. I'll break it down;

5a) -cp "comma separated list of class paths, surrounded by double quotes". To make your tool definition more portable, use eclipse "Varaibles' to calculate paths that are relative to your installation. In particular, I used 'workspace_loc' for workspace relative paths (like the src directory) and 'eclipse_home' for paths to gwt SDK stuff like gwt-user.jar (because I installed the SDK in the eclipse plugins folder). Here is my classpath part;

-cp "${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-user.jar;${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-dev.jar;${workspace_loc:\GWTFractionTest\war\WEB-INF\lib\gwtquery-1.1.0.jar};${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-codeserver.jar"

5b) Next is the name of the class that java.exe should run. This is the CodeServer class;

com.google.gwt.dev.codeserver.CodeServer 

5c) Next is the arguments to CodeServer. The first is the path to the src directly. For me, this is a workspace relative path;

-src "${workspace_loc:\GWTFractionTest\src}" 

5d) Finally, the module path (the class path to your gwt.xml file) Here is mine;

com.conceptua.fractiontest.FractionTest

Here is my full argument list;

-cp "${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-user.jar;${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-dev.jar;${workspace_loc:\GWTFractionTest\war\WEB-INF\lib\gwtquery-1.1.0.jar};${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-codeserver.jar" com.google.gwt.dev.codeserver.CodeServer -src "${workspace_loc:\GWTFractionTest\src}" com.conceptua.fractiontest.FractionTest

6) Select the 'Run' button to run the CodeServer. When I execute this in the console;

workDir: C:\Users\Ezward\AppData\Local\Temp\gwt-codeserver-6942784883227417581.tmp
binding: user.agent=safari
binding: compiler.useSourceMaps=true
binding: locale=en
Compiling module com.conceptua.fractiontest.FractionTest
   Validating units:
      Ignored 72 units with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   Computing all possible rebind results for 'com.google.gwt.useragent.client.UserAgentAsserter'
      Rebinding com.google.gwt.useragent.client.UserAgentAsserter
         Checking rule <generate-with class='com.google.gwt.editor.rebind.SimpleBeanEditorDriverGenerator'/>
            [WARN] Detected warnings related to 'com.google.gwt.editor.client.SimpleBeanEditorDriver'.   Are validation-api-<version>.jar and validation-api-<version>-sources.jar on the classpath?
            Specify -logLevel DEBUG to see all errors.
            [WARN] Unknown type 'com.google.gwt.editor.client.SimpleBeanEditorDriver' specified in deferred binding rule
   Compiling 1 permutation
      Compiling permutation 0...
      Source Maps Enabled
   Compile of permutations succeeded
Linking into C:\Users\Ezward\AppData\Local\Temp\gwt-codeserver-6942784883227417581.tmp\com.conceptua.fractiontest.FractionTest\compile-1\war\fractiontest; Writing extras to C:\Users\Ezward\AppData\Local\Temp\gwt-codeserver-6942784883227417581.tmp\com.conceptua.fractiontest.FractionTest\compile-1\extras\fractiontest
   Link succeeded
   Compilation succeeded -- 58.257s
Compile completed in 60831 ms
2012-07-01 12:37:03.184::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
2012-07-01 12:37:03.185::INFO:  jetty-6.1.x

The code server is ready.
Next, visit: http://localhxst:9876/
2012-07-01 12:37:03.274::INFO:  Started [email protected]:9876

I'm not sure why I get the initial '72 Units with compilations errors' but it seems to continue to successfully compile and run the server.

7) At this point, you should enter the given CodeServer url into Chrome. You will get a page that indicates the CodeServer is running and you can drag the book marklets to the bookmarks toolbar;

GWT Code Server
Drag these two bookmarklets to your browser's bookmark bar:
Dev Mode On Dev Mode Off
Visit a web page that uses one of these modules:
fractiontest
Click "Dev Mode On" to start development mode.

8) The next step is to get to your html file to run it. It apparently needs to be served by a separate webserver. I'm still working on that part.

Ed