kostas trichas
kostas trichas

Reputation: 3013

How to use GWT - RPC to Tomcat server

  1. Installed Tomcat 6
  2. Installed Eclipse + GWT plugin
  3. Created GWT project with sample generated code
  4. Compliled GWT project (GWT compile)
  5. Copied war (compiled) directory from eclipse's workspace to TOMCAT webapps/ROOT folder
  6. Run localhost:8080 at my browser

The sample.html page from the GWT project displays correct but when i try to make a server call an error occurs.

The catalina.out log at TOMCAT says:

Error deploying web application directory ROOT java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class com.tomcat.server.GreetingServiceImpl)

I guess there might be a problem at WEB_INF/web.xml at servlet definition, here's my web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>

  <!-- Servlets -->
  <servlet>
    <servlet-name>greetServlet</servlet-name>
    <servlet-class>com.tomcat.server.GreetingServiceImpl</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>greetServlet</servlet-name>
    <url-pattern>/tomcat/greet</url-pattern>
  </servlet-mapping>

  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>Tomcat.html</welcome-file>
  </welcome-file-list>

</web-app>

Upvotes: 2

Views: 3513

Answers (4)

Tony BenBrahim
Tony BenBrahim

Reputation: 7300

You can only get this error if the JDK version used to compile the classes is GREATER than the JDK version used by Tomcat. PERIOD. Pursuing any other avenue will be fruitless.

what is the environment JAVA_HOME set to?

Look at the Tomcat startup logs, what JDK is it using when it starts up, it is at the top of logs when it starts up

Now look at your Development tool that compiled the classes. It MUST be using a different JDK with a higher version for you to get this error.

Upvotes: 1

kostas trichas
kostas trichas

Reputation: 3013

I use GWT-SDK webAppCreator command (from terminal) and it generates all the files required to run on an external server like Tomcat.

I will provide the steps i followed in order to help others begin with simple GWT-TOMCAT development

TOMCAT

  1. Download a Tomcat version, i prefer Tomcat 6 http://apache.tsl.gr/tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-6.0.32.zip

  2. Follow the instructions for your specific operation system in order to install it. I followed this tutorial (MAC-OS) http://www.malisphoto.com/tips/tomcatonosx.html

GWT

  1. Download a GWT-SDK version (i use 2.0.4 which i find more stable and compatible with external sources like EXT-GWT library and TOMCAT) http://code.google.com/p/google-web-toolkit/downloads/list

  2. Open your TERMINAL if you are a UNIX user then change directory to the GWT-SDK you just downloaded

  3. Change permissions to run webAppCreator script. I usually modify permissions of all files by typing - > chmod 750 *

  4. Create a GWT project by executing in terminal -> ./webAppCreator -out MyProject com.myproject

  5. All files are automatically generated

  6. Switch directory to the project you just created, type in terminal -> cd MyProject

  7. Compile your project with the ant script provided by the GWT-SDK, type in terminal -> ant build

  8. Open you project and copy it's build.xml file, war/ contents to Tomcat's webapps/ROOT folder

  9. FINALLY open your browser type localhost:8080/ to run your project (It will open your project .html page by default because it is defined inside /WEB-INF/web.xml file)

Congratulations!

Upvotes: 1

Spidy
Spidy

Reputation: 40002

I had this same issue when I deployed to my Godaddy hosting server. It worked fine on my local machine but not when I deployed. I got the same exact error message. The problem is you compiled your code with a version of java that is newer then that of which Tomcat is using.

Install jdk1.5.0_22 (Or whatever your tomcat server is using)
Probably need to restart your machine
Eclipse->Window->Preferences->Java->Installed JRES->Add
Standard VM->Next
Browse to the directory of your jdk
Finish
Clean the project
Compile the project
Redeploy and cross your fingers!

This worked for me, if it doesn't for you then....ya...it should work. Good luck

Upvotes: 3

Eelke
Eelke

Reputation: 22083

You are probably compiling your classes with a newer jdk then the version tomcat is running on.

Upvotes: 3

Related Questions