Results 1 to 20 of 23
Thread: problems in running java file
- 02-13-2012, 06:58 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
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.
- 02-13-2012, 09:24 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
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...
- 02-14-2012, 03:06 AM #3
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
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.
- 02-14-2012, 09:47 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 02-14-2012, 02:40 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
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.
- 02-14-2012, 03:41 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 02-14-2012, 03:42 PM #7
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
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 :-)
- 02-14-2012, 04:16 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 02-14-2012, 04:36 PM #9
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
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.
- 02-14-2012, 05:00 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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...
- 02-14-2012, 05:20 PM #11
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
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 ?
- 02-14-2012, 06:36 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 02-15-2012, 08:40 AM #13
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
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. ?
- 02-15-2012, 09:24 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 02-15-2012, 09:31 AM #15
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
Re: problems in running java file
yeah i am using ECLIPSE IDE :-)
- 02-15-2012, 11:08 AM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 02-15-2012, 12:52 PM #17
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
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 ?
- 02-15-2012, 02:08 PM #18
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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?
- 02-15-2012, 03:14 PM #19
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
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
- 02-15-2012, 03:34 PM #20
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
New to java - Issues with running the .java file from flash drive
By seth_java in forum New To JavaReplies: 2Last Post: 09-21-2011, 09:33 AM -
Problems running my first GUI
By leonsas in forum AWT / SwingReplies: 2Last Post: 12-27-2010, 11:40 AM -
running problems
By babygina37 in forum EclipseReplies: 3Last Post: 04-20-2009, 04:59 AM -
JAVA ME - Problems compiling and running in Eclipse
By Nicsoft in forum EclipseReplies: 2Last Post: 03-20-2009, 10:58 AM -
Problems getting jar file running locally
By edpfister in forum Java AppletsReplies: 2Last Post: 03-09-2009, 08:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks