Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default problems in running java file

    When i try to run the java file for which is used for parsing the SQL statement as a normal java application there doesn't occur any problem.
    But where as when i try to run the same java file on the server by using it in a servlet there occurs a service exception in the server?
    <br/>
    What could be the reason for the problem?<br/>
    Server used: Apache Tomcat<br/>
    And the exception error occured was <br/>

    HTTP Status 500 -

    --------------------------------------------------------------------------------

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet execution threw an exception


    root cause

    java.lang.NoClassDefFoundError: gudusoft/gsqlparser/TGSqlParser
    demos.columnInWhereClause.ColumnInWhereClause.getW here(ColumnInWhereClause.java:15)
    demos.columnInWhereClause.ColumnInWhereClause.main (ColumnInWhereClause.java:11)
    controller.getNames.doPost(getNames.java:42)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)


    root cause

    java.lang.ClassNotFoundException: gudusoft.gsqlparser.TGSqlParser
    org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1680)
    org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1526)
    demos.columnInWhereClause.ColumnInWhereClause.getW here(ColumnInWhereClause.java:15)
    demos.columnInWhereClause.ColumnInWhereClause.main (ColumnInWhereClause.java:11)
    controller.getNames.doPost(getNames.java:42)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)


    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.


    --------------------------------------------------------------------------------

    Apache Tomcat/6.0.35

    And the java file which is tried accessing throught the servlet is as below.
    package demos.columnInWhereClause;

    import gudusoft.gsqlparser.EDbVendor;
    import gudusoft.gsqlparser.TGSqlParser;


    public class ColumnInWhereClause
    {

    public static void main(String[] args){
    getWhere("select * from weather where place=chennai");
    }
    public static void getWhere(String query)
    {
    gudusoft.gsqlparser.TGSqlParser sqlparser = new gudusoft.gsqlparser.TGSqlParser(EDbVendor.dbvmysql );
    sqlparser.sqltext =query;
    int i = sqlparser.parse( );
    if (i == 0)
    {
    WhereCondition w = new WhereCondition(sqlparser.sqlstatements.get( 0 ).getWhereClause( ).getCondition( ));
    w.printColumn();
    }
    else
    System.out.println(sqlparser.getErrormessage( ));

    }

    }


    I called the main method of the java file from the servlet.
    Expeting a positive reply.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: problems in running java file

    Where is the TGSqlParser class? Evidently it is not on the classpath, as the exception is pretty clear that the class cannot be found. I do not understand how the servlet is even accessing the ColumnInWhereClause class...

  3. #3
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: problems in running java file

    The TGSLParser class is available in the library as a jar file.
    But when i try to open it i cant modify and its asking source is missing.
    but when i run it as a java apps i am able to run without any problem. Can you tel me how to add it to the class path.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: problems in running java file

    Have you deployed the relevant jar file in the WEB-INF/lib directory?
    That directory is the default classpath for a web app and should contain all your dependent jar files.

  5. #5
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: problems in running java file

    When i try to import the jar file into the web-inf/lib a new project like is created for the jar file.
    And i have also placed the jar file under resources/libraries.

    And when i try to load again in the WEb-inf/LIB i am getting the error stating the jar file is already available.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: problems in running java file

    What do you mean by 'import the jar'?
    I mean, look at the Tomcat webapps/<your-app> directory and see if the jar file is in the WEB-INF/lib directory.
    If it isn't, then your deployment is incorrect.
    Why it is incorrect depends entirely on how you are creating your war, or how you are deploying.

  7. #7
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: problems in running java file

    Atlast found the problem with sleepless nights.

    We need to include the classpath in the server. just right click on project and select your server. and in the classpath tab include the other projects whichever you need along with the jar files.

    Loving solving these problems :-)

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: problems in running java file

    That sounds very wrong to me.
    I've never set the classpath for a webapp on Tomcat.
    All jars needed are deployed with the application.

    I suspect you've simply stuck some sticky tape over your real problem.

  9. #9
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: problems in running java file

    Nope the problem actually occurred in the service method of the servlet. So i tried to include the classpath in the server and that worked well for me. And i tried removing the classpath from the server and it dint work the same problem occured.
    Check out my previous posts you will come to know about the problem. The problem was not with the classpath of the web app it was with the classpath of the server. Plz check out once again and let me whether my assumption is correct.

  10. #10
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: problems in running java file

    The jar containing TGSqlParser is part of your web app, not Tomcat.

    Tomcat, by default, uses WEB-INF/lib as the classpath of your web app.

    You should therefore have the jar file in the WEB-INF/lib of your web app, which would then be visible in your app, and visible to the class loader used to load jars associated with web apps.

    By sticking it on the classpath for Tomcat you have made that jar file visible to all web apps on that server, which is a Bad Thing in all but the most noddy of cases.
    If you need to know, then imagine you have two apps on your server each reliant on a different version of a particular jar file...

  11. #11
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: problems in running java file

    OK but if i load the jar file in the WEB-INF/lib i am getting the error why is that so ?
    I understood what you meant. you mean to say that i have made the jar file generic and not specific for a web app rite ?

  12. #12
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: problems in running java file

    Yes.
    If it isn't picking it up from the WEB-INF/lib (and you have confirmed that is in the <tomcat installation>/webapps/<yourapp>/WEB-INF/lib, then your jar file is incorrect somehow.

    Which is why I was wondering how you are deploying this.

  13. #13
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: problems in running java file

    But when i try to import or place my jar file in the WEB-INF/lib folder it automatically gets loaded in Libraries folder in Reference Libraries folder similar to that of src. I am not able to place the jar file in the lib. When i try to import again i am getting the same error .
    And i used to right click on the ib folder and use import option to import the jar file.

    Tell me what can i do to solve the problem. ?

  14. #14
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: problems in running java file

    WHat do you mean "automatically gets loaded"?
    Are you running this via some IDE?

    In which case I would figure out how to set that up properly as it is not deploying correctly if that library is not getting deployed.
    That would be nothing to do with Tomcat, though.

  15. #15
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: problems in running java file

    yeah i am using ECLIPSE IDE :-)

  16. #16
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: problems in running java file

    OK.
    So (and I've not a got an Eclipse/Tomcat set up here) you add the library to the project as normal, via the build path properties bit.
    Assuming the project is set up as a web project a build should correctly populate your war file.
    Depending on the server plug in you are using for launching Tomcat will determine how that gets deployed.

  17. #17
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: problems in running java file

    Ah! I am using the WAMP server to start my server. And when never i make some changes the server automatically gets deployed. You mean to say that deploying is mainly used for intimating the server about the changes in the project rite ?

  18. #18
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: problems in running java file

    In real life (ie not in testing) you woudl take your war file and drop it into the webapps directory of your live Tomcat server.

    In a development situation you might have your IDE set up to point at a server and auto-deploy there so you can debug your app.
    That is usually via a plug in, in your case WAMP?

  19. #19
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: problems in running java file

    is it because we cant restart the server in a real life situation? And because of that we can deploy when never the changes are made to the web-app

  20. #20
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: problems in running java file

    Sometimes.
    Sometimes hot deploy (ie making changes without restarting the server) simply isn't an option because it doesn't work with certain changes.

    Anyway, have you figured out your problem?

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 09-21-2011, 09:33 AM
  2. Problems running my first GUI
    By leonsas in forum AWT / Swing
    Replies: 2
    Last Post: 12-27-2010, 11:40 AM
  3. running problems
    By babygina37 in forum Eclipse
    Replies: 3
    Last Post: 04-20-2009, 04:59 AM
  4. Replies: 2
    Last Post: 03-20-2009, 10:58 AM
  5. Problems getting jar file running locally
    By edpfister in forum Java Applets
    Replies: 2
    Last Post: 03-09-2009, 08:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •