0

I am running a WEB service program in eclips using Apache TomCat Server.I am running it manually.During this it will give me error that Can not find symbol LoginResource.class.

I have two file LoginResource.java and LoginApplication.java.Both files gets compiled but when I run them on server It giving me that error. When I directly run whole project on server it runs,But when I run the server manually it gives error.

To resolve this I put both files(.class) in same folderbut still same error. Anybody have solution to this. Following are my two .java files- LoginApplication---->

package com.login;

import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.routing.Router;

public class LoginApplication extends Application {

    public Restlet createInboundRoot() {
    Router router = new Router(getContext());
    router.attach("/login", LoginResource.class);

    return router;
    }
}

LoginResource--->

package com.login;

import org.json.JSONObject;
//import org.restlet.data.CharacterSet;
import org.restlet.data.Form;
//import org.restlet.data.Language;
//import org.restlet.data.MediaType;
import org.restlet.data.Parameter;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import java.sql.*;

public class LoginResource extends ServerResource {

    String name = "Login Example";


    public String getName()
    {
        return name;
    }


    protected Representation put(Representation input) {

        //Representation r = null;
        JSONObject jsonResult = new JSONObject();

        Connection con = null;
        String dbUrl = "jdbc:mysql://localhost:3306/loginDb";
        String driver = "com.mysql.jdbc.Driver";

        //String result = "Login Failed ...";

        try {

            Class.forName(driver).newInstance();
            con = DriverManager.getConnection(dbUrl, "loginDb", "loginDb");
            System.out.println("Connected to the database");

            Statement stm = con.createStatement();
            ResultSet rs = null;

            String inputText = input.getText();
            System.out.println(inputText);
            Form form = new Form(inputText);

            String email = "";
            String password = "";
            for (Parameter entry : form) {

                if(entry.getName().equals("email"))
                {
                    email = entry.getValue();   
                }

                if(entry.getName().equals("password"))
                {
                    password = entry.getValue();                            
                }
                System.out.println(entry.getName() + "=" + entry.getValue());
            }

         if(email.equals("") || password.equals(""))
         {
             System.out.println("EmailId or Password not provided");
             jsonResult.put("success", false);
             jsonResult.put("message", "EmailId or Password not provided");
         }
         else
         {
            //rs = stm.executeQuery("select * from users where email = '" + email + "' and password = '" + password + "'");
            String query = "select * from users where email='" + email + "' and password='" + password + "'";
            rs = stm.executeQuery(query);

            System.out.println("Query = " + query);

            if(rs.next())
            {
                query = "select * from users where email='" + email + "' and password='" + password + "' and verified = 1";
                ResultSet rs2 = stm.executeQuery(query);

                if(rs2.next())
                {
                    System.out.println("Logged In successfully");
                    jsonResult.put("success", true);
                    jsonResult.put("message", "Logged In successfully");
                }
                else
                {
                    System.out.println("Please confirm ");
                    jsonResult.put("success", false);
                    jsonResult.put("message", "Please confirm");
                }
                rs2.close();
            }
            else
            {
                System.out.println("In correct username or password");
                jsonResult.put("success", false);
                jsonResult.put("message", "In correct username or password");
            }

            /*r = new StringRepresentation(
                    jsonResult.toString(),
                    MediaType.APPLICATION_JSON,
                    Language.ALL,
                    CharacterSet.UTF_8);*/

            rs.close();
         }

        stm.close();
        con.close();

        } catch (Exception e) {
            e.printStackTrace();
        }


        System.out.println(jsonResult);
        return new StringRepresentation(jsonResult.toString());
    }

}
3
  • What do you mean by running the server manually ? Also could you provide some more information on what plugin you use in eclipse and some stack trace of the exception ?
    – Sridhar G
    Commented Apr 24, 2012 at 11:42
  • Manually means running the server from command prompt.In linux we have to run server manually.About stacktress only error is comming.I think LoginApplication.class doesnot found LoginResource.class file. Thats why this error-cant found symbol LoginResource.class. Commented Apr 24, 2012 at 11:53
  • Could you also mention which tomcat plugin you use in eclipse ?
    – Sridhar G
    Commented Apr 24, 2012 at 12:01

1 Answer 1

0

Problem cause: Class files must be placed in eclipse .metadata directory and not in tomcat webapp directory (it depends on what eclipse plugin you use)

Solution: Deploy your application(war file) in tomcat and now you should be able to start your application without error

1
  • But My application on Server then how should my files reside in Eclips.It should be in Webapp folder so that server can access it. Commented Apr 24, 2012 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.