LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   java.lang.NoClassDefFoundError (https://www.linuxquestions.org/questions/programming-9/java-lang-noclassdeffounderror-462389/)

robbbert 07-09-2006 03:12 PM

java.lang.NoClassDefFoundError
 
Hi, I'm trying to get JBoss Hibernate running, on Eclipse 3.1, on Ubuntu 6.06.
This is a detailed (and lengthy) problem description - it's very important to me to solve this.
Thank you indeed for your time and efforts. I need to resolve this, at any rate. Thanks again.

This is the Java code I'm trying to execute:
Code:

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Test
{
        public static void main(String[] args)
        {
                SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
        }
}

When running that code, I'm getting the error:
Quote:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:116)
at hibernate.generatedcode.postgres.world.Test.main(Test.java:11)
So where could (which??) Java (there are several versions installed, but only one should be active - see below) search for that JAR? -

1. By default, Java on Ubuntu is started via "/usr/bin/java", which is a link that points to "/usr/lib/j2sdk1.5-sun/bin/java", in my case, and that's allright.
"/usr/lib/j2sdk1.5-sun/lib" does contain the JAR file in question, "commons-logging-1.1.jar".

2. Anyways, - to make sure to match a working Java Virtual Machine, I'm now starting Eclipse using a custom command: "/usr/lib/j2sdk1.5-sun/bin/java -Xms40m -Xmx256m -jar /media/hde1/home/robert/eclipse-3.1.2-wtp/startup.jar -os linux -ws gtk -arch x86 -launcher /media/hde1/home/robert/eclipse-3.1.2-wtp/eclipse -name Eclipse -showsplash 600 -exitdata 460011 -vm /usr/lib/j2sdk1.5-sun/bin/java -vmargs -Xms40m -Xmx256m -jar /media/hde1/home/robert/eclipse-3.1.2-wtp/startup.jar".

Again, "/usr/lib/j2sdk1.5-sun/lib" does contain the JAR file in question, "commons-logging-1.1.jar".

3. In the project's "Java Build Path", I've added (a) "/usr/lib/j2sdk1.5-sun/lib/hibernate3.jar" (otherwise, the project wouldn't compile), and (b) "/usr/lib/j2sdk1.5-sun/lib/commons-logging-1.1.jar" (containing the class that could not be found).
I've also made sure both libraries are checked to be exported.

4. In the project's "Java Build Path", I've also added a reference to the variable "JRE_LIB", which points to "/usr/lib/j2sdk1.5-sun/jre/lib/rt.jar". That package that cannot be found, "commons-logging-1.1.jar", does exist in "/usr/lib/j2sdk1.5-sun/jre/lib/ext".

5. On my Ubuntu system, there's also some dubious folder named "/usr/share/java". There, mostly links exist, but additionally, some actual JAR files. I've added the JAR file in question, "commons-logging-1.1.jar", to it.

6. Java (in case some application would still ask "the system" for where to find Java) should be configured allright:
Quote:

robert@ubuntu:/$ sudo update-alternatives --config java
Password:

There are 6 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /etc/alternatives/kaffe-system/bin/java
* 2 /usr/lib/j2sdk1.5-sun/bin/java
3 /usr/bin/gij-wrapper-4.1
4 /usr/lib/jvm/java-gcj/jre/bin/java
+ 5 /usr/lib/j2se/1.4/bin/java
6 /usr/lib/j2sdk1.5-sun/jre/bin/java
7. I don't understand what the + sign means in the above quote, anyways, I'd also placed the offending JAR into "/usr/lib/j2se/1.4/lib/ext".

8. At some point of time, I'd also set the CLASSPATH property accordingly, pointing to "/usr/lib/j2sdk1.5-sun/jre/lib/ext", where "commons-logging-1.1.jar" resides. - No luck.

9. I've searched the web for similar issues, but anything doesn't seem to help for me.
Also, I haven't had such problems when using Eclipse on Windows (using other libraries), extensively.

------------------------
Still no luck!
I've spent a d*mned complete day on just trying to resolve that simple issue! And it's not going to stop! F*ck!!
------------------------

- Would anyone please be so nice to get me out of here? You see, I've tried alot, and I really need some assistance to get me productive again.

Sincerely
robbbert

robbbert 07-10-2006 02:05 PM

Another case:

I've added the Apache Axis default web app to Tomcat. - When I point the browser to that URL, the following error gets thrown:
Quote:

root cause

Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.ja va:105)
However, $JAVA_HOME is set perfectly right:
Quote:

robert@ubuntu:~$ echo $JAVA_HOME
/usr/lib/j2sdk1.5-sun

alred 07-10-2006 03:16 PM

your posting are quite long and left alone stuffs like apache and tomcat but no harm checking your javac , jar and javah and such executables in your usual */bin directories ...


//i'm not sure whether this can help you ...

.

robbbert 07-10-2006 04:02 PM

Quote:

but no harm checking your javac , jar and javah and such executables in your usual */bin directories
You mean I should check whether those files exist? - Of course they do! - Even $CLASSPATH and $JAVA_HOME are set correctly (and contain the offending JAR files) whenever I get those issues and check the paths!

alred 07-10-2006 04:16 PM

no files are as offending as how you mentioned i guess ...

can try something like /usr/bin/jar -V and for the rest of */bin/javac and such too ... probably they belong to gnu softwares ...

but if you have already got these right in the first place then the problems might lie somewhere else which i wouldnt know ...


//sorry , cant help you much ...


.

robbbert 07-14-2006 03:39 PM

Quote:

can try something like /usr/bin/jar -V and for the rest of */bin/javac and such too ... probably they belong to gnu softwares ...
That's right: These are symbolic links, (in my case) pointing to various Java virtual machines. I've cleaned that up to use the Sun 1.5 JDK (keyword: "configure-alternatives"), and now, at least Axis within Tomcat is working.

BTW, I really dislike how Ubuntu (my favorite Linux distribution) handles Java. When you install Sun Java (by Ubuntus repositories...), there shouldn't remain symbolic links to Kaffe Java, IBM Java, "some" Java, etc.

When you state, "java", "javah", "javac", "jar", etc., any of these programs should point to the same Java version.

Thanks

robbbert 07-16-2006 06:47 AM

Compiling JSPs with Tomcat works now. For almost two days I'd tried anything until finally I switched from that Tomcat version that came bundled with NetBeans to an original one.


All times are GMT -5. The time now is 06:50 PM.