Comple error in GWT when calling exteranl .jar

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Comple error in GWT when calling exteranl .jar

Postby ewinb » Fri Jun 04, 2010 6:32 am

I think I have a trivial problem with a trivial test case, but I am not able to find my error.

Narrative:
In my Eclipse workspace I have set up a Java class in its own project and package that has a few methods to perform some MySQL functions and return a result code. (name: com.adnorm.alib.client.JDBCconnect) It works fine and a separate test class can call it just fine. I have made the MySQL class a .jar file.

In the same workspace, but in a different project, I have defined a trivial GWT class (Login8) to put up a panel with two labels, two textboxes and a button. (username/password and submit). I have an on-click on the button to call my MySQL method to check the username and password. I have the proper import, and Eclipse indicates that it has found the MySQL method on the call statement. There are no source errors flagged by Eclipse. I have added the .jar file of my MySQL class to the Build list for this GWT program. I have not modified the gwt.xml file.

When I RunAs -> Compile GWT Application, I get the following error message:

Compiling module com.mycompany.login8.Login8
Validating newly compiled units
[ERROR] Errors in 'file:/C:/A/MyEclipse8.5/WS1/Login8/src/com/mycompany/login8/client/Login8.java'
[ERROR] Line 42: No source code is available for type com.adnorm.alib.client.JDBCconnect; did you forget to inherit a required module?
Finding entry point classes
[ERROR] Unable to find type 'com.mycompany.login8.client.Login8'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[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


Comment: Why is it looking for the source of JDBCconnect when I just want to reference the .jar? On the Build Path, on the Projects tab, I checked the 'Alib', project. I would have thought this sufficient. (WDISU?? -where did I screw up?) On the Build Path, on the Libraries tab, I included the .jar for JDBCconnect.



Here is the source of the GWT class 'Login8'. It is strictly just a test case and the only lines of code that I added were the import for JDBCconnect and to add the two lines in the OnClick:

package com.mycompany.login8.client;

import com.adnorm.alib.client.JDBCconnect;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;


/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Login8 implements EntryPoint {
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();

final FlowPanel flowPanel = new FlowPanel();
rootPanel.add(flowPanel, 6, 48);
flowPanel.setSize("250px", "186px");

final Label lblUsername = new Label("Username:");
flowPanel.add(lblUsername);

final TextBox textUsername = new TextBox();
flowPanel.add(textUsername);

final Label lblPassword = new Label("Password:");
flowPanel.add(lblPassword);

final TextBox textPassword = new TextBox();
flowPanel.add(textPassword);

final Button button = new Button("New button");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String result_string = JDBCconnect.getUserStatus(textUsername.getText(),textPassword.getText());
Window.alert("Alert:" + result_string);
// put stuff here!!
}
});
button.setText("Submit");
flowPanel.add(button);
}
}




My JDBCconnect code is: (the main method just permits stand-alone testing)


package com.adnorm.alib.client;

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

public class JDBCconnect {

private final static String drivername = "com.mysql.jdbc.Driver";
private final static String driverurl = "jdbc:mysql://192.168.198.21:3306/z1";
private final static String driverusername = "z1";
private final static String driverpassword = "z1";

private final static String USER_VALID = "V";
private final static String USER_NOSUCHUSER = "N";
private final static String USER_INVALIDPASSWD = "X";
private final static String USER_VALIDATIONPENDING = "P";
private final static String USER_ERROR = "X"; // Had error

public static Connection getConnection() throws Exception {
Class.forName(drivername);
Connection conn = DriverManager.getConnection(driverurl, driverusername, driverpassword);
return conn;
}


public static boolean isValidConnection(Connection conn) throws Exception {
if (conn == null) { // null connection object is not valid
return false;
}
if (conn.isClosed()) { // closed connection object is not valid
return false;
}
return true;
}

public static String getUserStatus(String username, String password) {
String return_code = USER_ERROR; // assume there was an error
Connection conn = null;
try {
conn = getConnection();
return_code = USER_NOSUCHUSER;
PreparedStatement s = null;
// System.out.println( "select for username/passwd: " + username + "/" + password);
s = conn.prepareStatement("SELECT user_username, user_password FROM user_master"
+ " WHERE user_username = ? AND user_password = ? " );
s.setString(1,username);
s.setString(2,password);
ResultSet resultSet = s.executeQuery ();
resultSet.last(); // position at last one
int rows = resultSet.getRow(); // set row count
s.close();
// System.out.println("Rows retrieved: " + Integer.toString(rows) );
if (rows == 1) {
return_code = USER_VALID;
}
} catch (Exception e) {
System.out.println(e.getMessage());
return_code = USER_ERROR;
return return_code;
}
return return_code;
}

public static void main(String[] args) {

Connection conn = null;
try {
conn = getConnection();
// System.out.println("conn=" + conn);
// System.out.println("valid connection = " + isValidConnection(conn));
String result_string = getUserStatus("aa","aa");
System.out.println("Result of: " + result_string);
} catch (Exception e) { // handle the exception
System.out.println(e.getMessage());
e.printStackTrace();
System.exit(1);
} finally { // release database resources
try {
conn.close();
} catch (Exception e) {
}
}
}
}
ewinb
 
Posts: 8
Joined: Tue May 11, 2010 1:56 pm

Re: Comple error in GWT when calling exteranl .jar

Postby Eric Clayberg » Fri Jun 04, 2010 12:24 pm

Note that this forum is specifically for questions about using GWT Designer.

General questions about GWT or how to structure your GWT application should be posted to Google's GWT forum.

ewinb wrote:I have added the .jar file of my MySQL class to the Build list for this GWT program. I have not modified the gwt.xml file.
...
On the Build Path, on the Projects tab, I checked the 'Alib', project. I would have thought this sufficient.

That is definitely not sufficient for GWT. You also need to update your gwt.xml file.

GWT has lots of rules about what is and is not allowed and how to structure your application (all covered in the GWT docs).
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Comple error in GWT when calling exteranl .jar

Postby ewinb » Fri Jun 04, 2010 2:06 pm

Eric-

Thanks for the reply.
I had hoped to just tell the Build dialog about the .jar and then be able to use the methods in it, just like I do with JDBC. None of these external methods I am using refer to any GWT functions.

On a hunch, I added an "inherits" line in the Login8.gwt.xml file that gave the full name of my MySQL class. When I attempt to compile the Login8.java code, it fails with an error that it is unable to find the gwt.xml file for the MySQL class.

I have been over the documentation that I could find. It would be far more helpful to point me to a specific section than just an overly broad suggestion to just RTFM. Based on the entries I can find with Google about "gwt error external jar", this is a very common problem and the sheer volume should be proof that it is an issue that needs to be addressed with concrete examples and explanations that are easy to find. Either that or it shows a function that needs to be added to the Eclipse plugin. Having the customer resorting to unproven third-party web sites for unsupported code hacks because he can't find the answer where it should be easily found is not satisfactory.

I found this site to be somewhat helpful, but after adapting my application to it, I am still failing to compile: http://www.vogella.de/articles/GWT/ar01s07.html I have no idea if this site is telling me the truth or leading me astray.

I have set up a workspace with just the example test classes and gwt code. I changed the name slightly as this was an entirely new workspace. I would be happy to upload it somewhere for someone to look at. This is a simple and generic test case. It would make a great HOWTO for anyone who would point out what needs to be fixed or added. I am dead in the water right now.
ewinb
 
Posts: 8
Joined: Tue May 11, 2010 1:56 pm

Re: Comple error in GWT when calling exteranl .jar

Postby Eric Clayberg » Fri Jun 04, 2010 6:52 pm

ewinb wrote:It would be far more helpful to point me to a specific section than just an overly broad suggestion to just RTFM
...
I am dead in the water right now.

In that case, I strongly encourage you to follow my earlier suggestion of posting your question to Google's GWT forum. This forum is not the appropriate place for general GWT questions like this. The Google GWT forum is the appropriate place.

As to your suggestion that I should have pointed you to the exact portion of the relevant Google GWT docs, I think that presupposes that I have a mental index of all the Google GWT docs at my fingertips. I don't. I know that topic is covered because I have run across it in the past. Finding the exact link for you would require spending time digging back into those docs. Frankly, we do not have the time to support both GWT Designer (our product) and GWT itself (not our product) in this forum.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Comple error in GWT when calling exteranl .jar

Postby ewinb » Thu Jun 17, 2010 11:32 am

Eric-

Upon review and further digging, yes you were exactly right in your recommendation.

It turns out that calling an external .jar file is easy, that is if the method being called is not in the same source path as the GWT client. If the java source of the .jar being called is in this path, the GWT compiler will try to compile it and when it fails the error message is misleading. If I can make a suggestion to add a sentence to your documentation to note this 'gotcha'. This drove me nuts, and in turn I am sorry for getting a bit snippy with Instantiations over it. I know now this is really a GWT quirk.
ewinb
 
Posts: 8
Joined: Tue May 11, 2010 1:56 pm

Re: Comple error in GWT when calling exteranl .jar

Postby Eric Clayberg » Fri Jun 18, 2010 5:15 am

OK. What would be the exact sentence you would like to see added and what doc page(s) should it be added to?
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to GWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest