RSSAll Entries Tagged With: "java"

Issue configuring log4j in Tomcat

Hi Friends,

Issue 1 :

I was trying to set up log4j for a REST application I wrote and got the below exception. [ I’m not pasting the complete exception ]

[html]</pre>
Apache Tomcat/7.0.64 – Error report HTTP Status 500 – Servlet.init() for servlet Jersey Web Application threw exceptiontype Exception reportmessage Servlet.init() for servlet Jersey Web Application threw exceptiondescription The server encountered an internal error that prevented it from fulfilling this request.exception javax.servlet.ServletException: Servlet.init() for servlet Jersey Web Application threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Unknown Source) root cause java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger; java.lang.Class.getDeclaredFields0(Native Method) java.lang.Class.privateGetDeclaredFields(Unknown Source) java.lang.Class.getDeclaredFields(Unknown Source) org.glassfish.jersey.internal.util.ReflectionHelper$4.run(ReflectionHelper.java:306) org.glassfish.jersey.internal.util.ReflectionHelper$4.run(ReflectionHelper.java:303) java.security.AccessController.doPrivileged(Native Method) org.glassfish.jersey.server.model.IntrospectionModeller.checkResourceClassFields(IntrospectionModeller.java:210) org.glassfish.jersey.server.model.IntrospectionModeller.doCreateResourceBuilder(IntrospectionModeller.java:137)
<pre>[/html]

I was able to resolve the above issue using the below steps :-

Right Click on the Project -> Properties -> Deployment Assembly -> Add -> Java Build Path Entries ( Make sure you add log4j jar to the Build Path ) & select the logj4 jar.

Note : By using the above steps what you are doing is putting the log4j jar in the classpath, specifically in the WEB-INF/lib of your deployed application.

Issue 2 :

The second issue what I faced is; the project was not able to find the log4j.properties file which I had created.

Solution : Place the log4j.properties file under src -> main -> resources folder & you can use

PropertyConfigurator.configure(“log4j.properties”);

 

 

Hibernate Project Errors – Java – MYSQL 5.0

In this article I am sharing my experience on running my first Hibernate Project.

java-hibernate

I started with my first Hibernate project and followed the steps as instructed within the Tutorial. But on running it I was getting the below error.

[html]

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread “main” org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1453)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1475)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1011)
at com.hibernate.chapter.HelloEmployee.main(HelloEmployee.java:18)

[/html]

Resolution:

I had to spent some time to figure out what I missed and finally the issue was resolved.

The mistake I did was I pasted hibernate.cfg.xml and log4j.properties files thru Eclipse IDE and file got placed within the project root path as you see below.

img

The classpath would be SET to src and the project will search for these files within the scr folder on compile time; so you would need to move the two files manually into the src folder which will resolve the issue.

Hope this helped !

Eclipse – Failed to load the JNI shared library “C:/JDK/bin/client/jvm.dll”

Hello Team,

I found something interesting on configuring my new laptop for JAVA & Eclipse.

I followed the normal procedure and installed JAVA and Eclipse but when I tried launching Eclipse got the below error.

eclipse

Error Message – Failed to load the JNI shared Library !

Issue : The issue is caused due to the mismatch between the JAVA & Eclipse bit versions. I installed 64 bit jdk and tried launching Eclipse built for x86 version. :)

Resolution : Install the same version of JAVA & Eclipse too resolve the issue. Recommended version is x86.

Hope this helps !