PDA

View Full Version : GWT+MySQL web application: compiling errors



guim
8 Nov 2011, 8:51 PM
Hi all,




I'm making a GWT+MySQL web application, with Eclipse and Tomcat. I tried to modified a code from internet. Wen I run my project as a Web application (Debug As mode), I'm having the following compilation errors:










[ERROR] [deuxiemeapplicationgwt] - Errors in 'file:/C:/Users/tfgui/workspace/DeuxiemeApplicationGwt/src/com/essai/client/DeuxiemeApplicationGwt.java': [ERROR] [deuxiemeapplicationgwt] - Line 50: No source code is available for type org.apache.catalina.User; did you forget to inherit a required module?


[ERROR] [deuxiemeapplicationgwt] - Errors in 'file:/C:/Users/tfgui/workspace/DeuxiemeApplicationGwt/src/com/essai/client/ConnexionBDAsync.java': [ERROR] [deuxiemeapplicationgwt] - Line 10: No source code is available for type org.apache.catalina.User; did you forget to inherit a required module?

[ERROR] [deuxiemeapplicationgwt] - Unable to find type 'com.essai.client.DeuxiemeApplicationGwt': [ERROR] [deuxiemeapplicationgwt] - Hint: Previous compiler errors may have made this type unavailable or [ERROR] [deuxiemeapplicationgwt] - 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


[ERROR] [deuxiemeapplicationgwt] - Failed to load module 'deuxiemeapplicationgwt' from user agent 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.23) Gecko/20110920 Firefox/3.6.23' at 127.0.0.1:63398




These are the files code:


==================================================
//Synchronization file
package com.essai.client;

import com.google.gwt.user.client.rpc.RemoteService;
import org.apache.catalina.User;

public interface ConnexionBD extends RemoteService
{
public User authenticateUser(String Utilisateur, String motDePasse);
}

==================================================
//Synchronization file
package com.essai.client;

import org.apache.catalina.User;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface ConnexionBDAsync {

public void authenticateUser(String Utilisateur, String motDePasse,
AsyncCallback<User> callback);
}

==================================================
//EntryPoint file

package com.essai.client;

import org.apache.catalina.User;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.*;

public class DeuxiemeApplicationGwt implements EntryPoint, ClickListener, IsWidget {
private ConnexionBDAsync rpc;
private TextBox usernameBox;
private TextBox passwordBox;
private Button OK;
public DeuxiemeApplicationGwt() {
rpc = (ConnexionBDAsync) GWT.create(ConnexionBD.class);
ServiceDefTarget target = (ServiceDefTarget) rpc;
// The path 'MySQLConnection' is determined in ./public/LoginScreen.gwt.xml
// This path directs Tomcat to listen for this context on the server side,
// thus intercepting the rpc requests.
String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnection";
target.setServiceEntryPoint(moduleRelativeURL);
initGUI();
}
public void onModuleLoad() {
RootPanel.get().add(this);
}

private void initGUI() {
Grid g = new Grid(3, 2);
usernameBox = new TextBox();
passwordBox = new TextBox();
OK = new Button("OK");
g.setWidget(0, 0, new Label("Username: "));
g.setWidget(0, 1, usernameBox);
g.setWidget(1, 0, new Label("Password: "));
g.setWidget(1, 1, passwordBox);
g.setWidget(2, 1, OK);
}
public void onClick(Widget sender) {

if (sender.equals(OK)) {
AsyncCallback<User> callback = new AuthenticationHandler<User>();
rpc.authenticateUser(usernameBox.getText(),
passwordBox.getText(),
callback);
}
}
private class AuthenticationHandler<T> implements AsyncCallback<User> {
public void onFailure(Throwable ex) {
RootPanel.get().add(new HTML("RPC call failed. :-("));
}
public void onSuccess(User result) {
//do stuff on success with GUI, like load the next GUI element
}
}
@Override
public Widget asWidget() {
// TODO Auto-generated method stub
return null;
}
}

==================================================
package com.essai.server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import org.apache.catalina.User;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.essai.client.Utilisateur;
import com.essai.client.ConnexionBD;

public class ConnexionMySQL extends RemoteServiceServlet implements ConnexionBD
{
private Connection conn = null;
private String status;
private String url = "jdbc:mysql://localhost/gestionpatients";
private String utilisateurBD = "root";
private String motDePasseBD = "";

public ConnexionMySQL()
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, utilisateurBD, motDePasseBD);
}
catch (Exception e)
{

}
}

public User authenticateUser(String utilisateurTemp, String motDePasseTemp)
{
Utilisateur utilisateur;
try
{
PreparedStatement ps = conn.prepareStatement(
"select readonly * from docteurs where Noms = \"\" + user + \"\" AND " + "ID = \"\" + pass + \"\""
);
ResultSet result = ps.executeQuery();
while (result.next())
{
utilisateur = new Utilisateur(result.getString(1), result.getString(2));
}
result.close();
ps.close();
}
catch (SQLException sqle)
{
//Comportement en cas d'erreur
}
return authenticateUser(utilisateurTemp, motDePasseTemp);
}
}
==================================================
//Utilisateur.java: user configuration
package com.essai.client;

import com.google.gwt.user.client.rpc.IsSerializable;
//import java.io.Serializable;

public class Utilisateur implements IsSerializable
{
private String nomUtilisateur;
private String motDePasse;
@SuppressWarnings("unused")
private Utilisateur() {}

public Utilisateur(String utilisateur, String motDePasse)
{
this.nomUtilisateur = utilisateur;
this.motDePasse = motDePasse;
}
}
==================================================
//XML file

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='deuxiemeapplicationgwt'>
<!-- 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="com.essai.client.DeuxiemeApplicationGwt.server.ConnexionMySQL"/>

<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"/>


<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>

</module>
==================================================

The project structure can be seen here: http://tonguim.free.fr/divers/imgGWTtomcat.jpg



Thank you for your help.

micgala
9 Nov 2011, 12:35 AM
Hi.
Are you new to GWT?

You cannot use any 3rd party libraries that are not prepared for GWT. This means, that does not "expose" its contents with the help of the gwt.xml file.

I would recomment you reading this:

http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasics.html

Regards,
Michel.