Zdanek devBlog+

July 1, 2010

NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder

Filed under: java, maven — Tags: , , — zdanek @ 10:20

I get error while running code with Hibernate 3.5.x

java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:165)
at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:127)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at pl.bartekzdanowski.MyTest.setUp(MyTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
… 43 more

The solution is described on SLF4j page. Simply you have to add slf4j-api with wersion greater than 1.5.6. In maven pom.xml you can declare slf4j explicitly:

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

April 26, 2010

Zero Cobertura coverage

Filed under: develop, maven — Tags: , , — zdanek @ 14:58

Recently I had zero code coverage during tests. I had a maven2 project (under maven 1.0.9), with default cobertura version, which was 1.9.

All reports were generated normally except all code coverage was zero (0).

The reason was somehow buggy cobertura version 1.9.
After I put cobertura-maven-plugin configuration into my pom.xml specifying cobertura version 2.4


<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
</plugin>

all went well and finally I had my non-zero coverage :D

(Edit: I’ve added some pretty screenshots :])

July 1, 2009

“Cannot allocate memory” while compiling project with maven

Filed under: develop, java, maven — zdanek @ 13:48

While compiling my project with Maven I got sometimes on my Linux (Gentoo actually) box the following error

[ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO] Error reading assembly descriptors: Error reading descriptor at: /var/www/app_src/src/main/assembly/package.xml: Cannot run program “env”: java.io.IOException: error=12, Cannot allocate memory

This was caused by not enough amount of swap memory on linux. After increasing to double size of physical memory all problems are gone.

I was inspired by this entry of Hudson Wiki.

Powered by WordPress

WP-Highlight