-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: java.lang.NoClassDefFoundError in running HelloWorld Example
PostPosted: Sun Nov 18, 2007 2:22 pm 
Newbie

Joined: Mon Nov 05, 2007 11:07 pm
Posts: 4
Hi Guys,
I tried running the first HelloWorld example given in Java Persitence with Hibernate.I used the same ant script.I am able to compile,export the ddl to HSQLDB but when i say ant run as said in the book i am getting the following error java.lang.NoClassDefFoundError.I have installed jdk1.5 in C:\Java\jdk1.5 and ant in C:\ant.

My PATH variable points to C:\Java\jdk1.5\bin;C:\ant\bin
CLASSPATH variable points to C:\Java\jdk1.5\lib;C:\Java\jdk1.5\bin
JAVA_HOME points to C:\Java\jdk1.5
ANT_HOME points to C:\ant

I feel this is some thing related to setting paths. Can any one please help me as i am not able to figure out what is the problem

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 2:14 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
your classpath (which btw is NOT used by ANT, it sets its own) doesn't contain any of the Hibernate jar (or dependencies), nor does it contain your own classes.
What it does contain it should not, NEVER point the classpath to any directory internal to the JDK installation.

In fact one should rarely if ever set a global classpath at all, rather set it during JVM startup to the specific values required for the application you're running.


Top
 Profile  
 
 Post subject: java.lang.NoClassDefFoundError still persists
PostPosted: Mon Nov 19, 2007 10:02 am 
Newbie

Joined: Mon Nov 05, 2007 11:07 pm
Posts: 4
Thanks a lot for the quick turn around.Actually i am using build.xml as specified in the book.The build.xml adds all the jars and libs specific to Hibernate to the classpath declaration as shown below:-

<project name="HelloWorld" default="compile" basedir=".">

<property name="proj.name" value="HelloWorld"/>
<property name="proj.version" value="1.0" />

<!-- Global properties for the build -->
<property name="src.java.dir" value="src" />
<property name="lib.dir" value="lib"/>
<property name="build.dir" value="bin"/>

<!-- Classpath declaration -->
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
<include name="**/*.zip"/>
</fileset>
</path>

<!-- Useful declarations -->
<patternset id="meta.files">
<include name="**/*.xml"/>
<include name="**/*.properties"/>
</patternset>

<!-- Clean up-->
<target name="clean">
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
</target>

<!-- Compile Java Source -->
<target name="compile" depends="clean">
<mkdir dir="${build.dir}"/>
<javac
srcdir="${src.java.dir}"
destdir="${build.dir}"
nowarn="on">
<classpath refid="project.classpath"/>
</javac>
</target>

<!-- Copy metadata to build classpath -->
<target name="copymetafiles">
<copy todir="${build.dir}">
<fileset dir="${src.java.dir}">
<patternset refid="meta.files"/>
</fileset>
</copy>
</target>

<!-- Run HelloWorld -->
<target name="run" depends="compile,copymetafiles"
description="Build and run HelloWorld">
<java fork="true"
classname="hello.HelloWorld"
classpathref="project.classpath">
<classpath path="$(build.dir}"/>
</java>
</target>

</project>

The other thing what i want to tell is i have no compilation problems . I am able to compile and see the class files but when i say ant run then i am getting java.lang.NoClassDefFoundError: hello/HelloWorld exception.
Kindly help me as to how to go about fixing this problem............


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 9:44 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
And what class exactly can't it find?
You're missing a jarfile somewhere, but with the incomplete information you're supplying it's impossible to tell which.

The jars needed at runtime aren't necessarilly the same as the ones needed at compile time btw.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.