Category Archives: Eclipse

The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [31] in the generated java file: [H:\eclipseWorkspace\J2EEspace\GlossaryPortal\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Spring3HibernateApp\org\apache\jsp\WEB_002dINF\views\index_jsp.java]
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:476)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

The below line from the generated java file causing the issue from _jspInit() method

_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();

Previous to this exception, I was facing the below exception

java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

To resolve this, I have downloaded the following JAR files from the web and placed it in /WEB_INF/lib folder

1) jsp-api-2.0.jar
2) jstl-1.2.jar

But you know, the jsp-api-2.0.jar is now lead to the exception “The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory”.

Solution

We should refer the target runtime in our project, not copy some libraries of an arbitrary servletcontainer make/version into our project. It would make our project incompatible with servletcontainers of a different make and/or version.

As simple, if you are using Tomcat 7 as server, then refer the jsp-api.jar from your Tomcat home directory’s lib folder. Don’t arbitrarily download some container version’s jsp=api file.

The project jar files should compatible with your servlet containers, which is the Tomcat Server that you are using as the Target Runtime.

So

You need to reference a server runtime in your project.

In Eclipse:

1) Choose “Project | Properties | Java Build Path | Libraries Tab”
2) Click “Add Library | Server Runtime | Apache Tomcat 7”
3) Click OK.
4) Clean your project, and build it again (“Project | Clean”, then “Project | Build All”)

That should do it!

Happy Learning 🙂

Advertisements

Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver

I am trying to connection my java web application to the Oracle9i database.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/config/sdnext-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

Solution

Make sure you have the ojdbc14.jar in your run time classpath.

Download the same from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc9201-092698.html

Happy Learning 🙂

java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;

Caused by: java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredFields(Unknown Source)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:270)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:139)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:403)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:879)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
... 20 more

Solution

Adding the commons-logging.jar to the class path will solve the problem.

Download the same from http://commons.apache.org/proper/commons-logging/download_logging.cgi

Happy Learning 🙂

SEVERE: Servlet /Spring3HibernateApp threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

I was working on the Spring MVC example. When I deployed my Spring web application into the Apache Tomcat 7 server, I end up with the following exception


Oct 12, 2014 8:24:01 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /Spring3HibernateApp threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:530)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:512)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5229)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5516)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Solution

ClassNotFoundException should always makes you to think “JAR is missing”. That is, the eclipse could not able to locate the class file ‘DispatcherServlet” here. The ClassNotFoundException clearly indicates that you are missing org.springframework.web.servlet classes.

So make sure the Spring MVC JAR files is available in the classpath. The Spring JARs and all their dependencies should be in your /WEB-INF/lib.

Add all JAR files in the Project build path, which is, Right-click on Project -> Properties -> Java Build Path -> Libraries. Add all external JARS as like either user library or web app libraries. Click on “Add External JARs” to add all the JAR files.

Even after this, if the exception occurs, try the below instructions

1) Project Properties -> Deployment Assembly
2) Add -> Java Build Path Entries
3) You should now see the list of libraries on your build path that you can specify for inclusion into your finished WAR.
4) Select the ones you want and hit Finish.

Happy Learning 🙂

eclipse.exe is not a valid Win32 application

Recently, I have downloaded the eclipse IDE for Java EE Developers package from

https://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/lunar

I have downloaded the Eclipse’s Windows 64-bit package version as I have windows XP operating system with x86 processor.  In Eclipse website, they provide 32 bit and 64 bit version of eclipse packages.  I am not sure which one to download.  I blindly downloaded 64 bit eclipse package and unzipped in my machine.

When I try to run the eclipse.exe, I got an error message “eclipse.exe is not a valid Win32 application”.

It means that the eclipse instance’s bit version does not match with the installed JVM’s bit version. To resolve this issue, we need to identify whether the installed JVM runs on 32 bit or 64 bit windows version.

Refer the following link to identify what is the bit version installed JVM supports,

http://saravananmtech.wordpress.com/2014/08/13/how-to-identify-the-installed-jvm-is-32-bit-or-64-bit/

We get error message if the Java instance does not support the desired version.

Based on that, we can download the right eclipse bit version package.  I have identified that my JVM runs on 32 bit version. So I have downloaded the Eclipse’s windows 32-bit version package.  Finally, the issue has been resolved.  🙂

what is the difference between Eclipse Europa and Ganymede?

It is all about versions

Here’s a quick reference on Eclipse releases and names.

3.0 28 June 2004
3.1 28 June 2005
3.2 Callisto 30 June 2006
3.3 Europa 29 June 2007
3.4 Ganymede 25 June 2008
3.5 Galileo 24 June 2009
3.6 Helios 23 June 2010
3.7 Indigo 28 June 2011

If you see “letters” in conjunction with a version number, this is what they mean:

On click of submit button, Servlet has been called twice. Why?

This can happen if you are calling the javascript function which does document.formName.submit() but the form itself also has an action attribute. Therefore, the form actually gets submitted twice. If you are submitting the page from the javascript, remove the action attribute from the form tag.

if javascript function does document.formName.submit(),

Ensure that the <input type = “submit”> should not be used in <form></form>

In the following, it is reverse

I used <input type = “submit”> in <form></form> but removed the document.formName.submit() from javascript function.

Example:

function callValidation()
{
if( validateDetails() )
{
document.frmLoadEmpDetails.action = “/DailyActivityLogger/TimeSheetRecorder”;
}
}

<form name=”frmTimeSheet”>

callValidation()”/>

</form>

how to define classpath for eclipse

Right click on a Project. Go Properties->Java Build Path. The Projects tab is for selecting other Projects the current Projects depends on - i.e. needs the class files. The Libraries tab is for adding external jars or creating and adding Eclipse libraries (which are a collection of jars).

When you're done setting it up you can look at the .classpath file in the Project root directory to see what you've done. But don't edit this file directly.

eclipse.exe has encountered a problem and needs to close.

Are you receiving the following window while launching eclipse.exe,

Solution:

you need to supply the path to the java executable in the vm parameter, not the path to the directory containing the executable.  For example, Try something like “C:\Java\jre1.6.0_02\bin\javaw.exe” for -vm parameter in eclipse.ini file.

If you are planning on doing Java development in Eclipse, it is recommended that you point at a jdk and not a jre so that you can have source attached to the runtime library classes/methods.

In the end, If nothing works, reinstall Java (jdk) and launch eclipse.exe.  100% it will work.

Other ways:

1. Try installing it into a clean directory (rather than on top of an existing Eclipse install).

2. here’s an eclipse.ini may works:

-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256m
-vm
c:/opt/jdk-1.6.0/jre/bin/client/jvm.dll
-vmargs
-Xms40m
-Xmx256m

3. you can try launching the jar that opens Eclipse App.
In my case it was the file
…/eclipse/plugins/org.eclipse.equinox.launcher_1.0.1.R33x_v20070828.jar
So,
“java -jar plugins/org.eclipse.equinox.launcher_1.0.0.v20070208a.jar”

4. Here is the eclipse.ini works for me

For more information,

http://wiki.eclipse.org/index.php/Equinox_Launcher

===================================================