Webservice reference in servlet fails with "cannot be resolved to a type"

Posted on 2014-09-18
Last Modified: 2014-09-24
I am trying to create a servlet (tomcat) that accesses a database, then a USDA web service. I've successfully deployed/tested the database connectivity. When I added the web service access, eclipse reports the problem: AwdbWebService_Service cannot be resolved to a type. I think I am referencing the service, not a type--anyway, it won't resolve as a service instance with whatever I am doing incorrectly. I generated the AwdbWebService package from a wsimport from the wsdl . Please advise.

The error is tripped by this line (#74):

AwdbWebService_Service lookup = new AwdbWebService_Service(wsURL,new QName("","AwdbWebService"));

 package localdomain.localhost;

 import java.math.BigDecimal;
 import; //added for usda webservice

 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.logging.Logger;

 import javax.annotation.Resource;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.sql.DataSource;

 import javax.xml.namespace.QName;       // added for usda webservice
 import usda.nrcs.wcc.awdbWebService.*;

 @WebServlet(value = "/MyServlet")
 public class MyServlet extends HttpServlet {

   // use this for usda reservoir station values later
   static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

   protected final Logger logger = Logger.getLogger(getClass().getName());
   @Resource(name = "jdbc/mydb", lookup = "jdbc/mydb")
   private DataSource dataSource;

   public void init(ServletConfig config) throws ServletException {
      System.out.println(getClass().getName() + ".init");

  protected void service(HttpServletRequest req, HttpServletResponse resp) throws  ServletException, IOException 
    PrintWriter writer = resp.getWriter();


    Connection conn = null;
    try {
        writer.println("Datasource: " + dataSource + "<br/><br/>");
        conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rst = stmt.executeQuery("select 1");
        while ( {
            writer.println("Resultset result: " + rst.getString(1) + "<br/><br/>");
        writer.println("SUCCESS to access the datasource");

        // Now try accessing usda
        URL wsURL = new URL("");

        AwdbWebService_Service lookup = new AwdbWebService_Service(wsURL,new QName("","AwdbWebService"));
        m_webService = lookup.getAwdbWebServiceImplPort();

    } catch (Exception e) {
    } finally {
        if (conn != null) {
            try {
            } catch (Exception e) {


Open in new window

Question by:ditallop
  • 5
  • 3
LVL 86

Accepted Solution

CEHJ earned 500 total points
ID: 40330684
import usda.nrcs.wcc.awdbWebService.*;

Open in new window

Try using the IDE to dig into that to get the type that it's telling you is missing. I suspect you won't be able to, so , if so, there's something wrong with the way you're pointing at the generated classes.

Author Comment

ID: 40330784
It thinks awdbwebservice is a type -- the wizard keeps popping up for me to define a new class. I've got plenty of those under the imported package! :) The import usda.nrcs.wcc.awdbWebService.* package has about 2 dozen method classes.  I just rebuilt it all again from the wsdl--on c:\  to keep it pure.  The full path it generated:
c:\gov\usda\nrcs\wcc\awdbWebService.  I removed the old package location from the project, this time pointing to the one I just created. This time the import line looks like:  import gov.usda.nrcs.wcc.awdbWebService.*;  Same maddening results.

Here's the import statement:
wsimport -p gov.usda.nrcs.wcc.awdbWebService -s c:\

Author Comment

ID: 40330798
to answer your direct suggestion, there isn't any additional info as to what type it thinks it needs to resolve to. just that it thinks i'm referencing one.
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

LVL 86

Expert Comment

ID: 40330863
Don't import .* Import each type you use

Author Comment

ID: 40330918
alright, I'll try that.

Assisted Solution

ditallop earned 0 total points
ID: 40334115
You are correct about the import. Thanks so much for your help ! :)

For those following this thread:

The package statement at the start of the java classes I generated with wsimport begins with:

package gov.usda.nrcs.wcc.awdbWebService

My import statement however, looked like this: import usda.nrcs.wcc.awdbWebService.*;

In essence, I placed the source @ the wrong level and defined the build config to point incorrectly for the package references defined in the java classes. I removed the build reference, then moved the tree to begin pointing on the gov level. Now that there wasn't a mismatch, the unresolved type error vanished.
LVL 86

Expert Comment

ID: 40334260
Good. Furthermore, as i hinted above, its bad practice to import .* All classes should be named explicitly. If you're using an IDE, there's no excuse, as something like 'Fix imports' will do that for you automatically

Author Closing Comment

ID: 40341137
While CEHJ identified the import as a problem, the details I've outlined in exactly why would be helpful to anyone following this thread with a similar issue.

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adjust the position 3 60
javap bin 2 34
map related example 6 48
maven module vs maven project 3 23
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you haven’t already, I encourage you to read the first article ( in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question