?
Solved

Java application with Hibernate and Mysql

Posted on 2006-04-27
23
Medium Priority
?
464 Views
Last Modified: 2013-11-23
Hi,
 I'm trying to learn how to use Java with Hibernate and MySQL and found this tutorial online.
http://www.laliluna.de/first-hibernate-example-tutorial.html
I downloaded the code and followed all  the  steps and built the project in eclipse
Now, when I try to run the TestExample.java file I get this error.


C:\>cd FirstHibernateExample\bin\de\laliluna\example

C:\FirstHibernateExample\bin\de\laliluna\example>java TestExample
Exception in thread "main" java.lang.NoClassDefFoundError: TestExample (wrong na
me: de/laliluna/example/TestExample)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I searched online and saw that a lot of people said this was because of incorrect classpath settings but mine are set correcty
C:\>cd JavaTest

C:\JavaTest>java HelloWorld
Hello, World
C:\JavaTest>cd ..

Anything else that I might be missing?
0
Comment
Question by:BrijBhasin
  • 9
  • 8
  • 4
  • +1
23 Comments
 
LVL 92

Expert Comment

by:objects
ID: 16558259
try:

java de.laliluna.example.HelloWorld

and make sure your class is in a directory that matchs the package hierarchy
0
 
LVL 92

Expert Comment

by:objects
ID: 16558277
ie.
cd FirstHibernateExample
java de.laliluna.example.HelloWorld
0
 

Author Comment

by:BrijBhasin
ID: 16558311
ok HelloWord gives the same error when run under the package hierarchy
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 16558326
please what you run and the error
also where HelloWorld.class is
0
 

Author Comment

by:BrijBhasin
ID: 16558363
C:\FirstHibernateExample>java de.laliluna.example.HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: de/laliluna/example/H
elloWorld

HelloWorld.Class is in the same directory /de/laliluna/example
0
 
LVL 92

Expert Comment

by:objects
ID: 16558384
try:

java -cp c:\FirstHibernateExample java de.laliluna.example.HelloWorld

or add C:\FirstHibernateExample to your classpath
0
 

Author Comment

by:BrijBhasin
ID: 16558394
C:\FirstHibernateExample>java -cp de.laliluna.example.HelloWorld
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -client       to select the "client" VM
    -server       to select the "server" VM
    -hotspot      is a synonym for the "client" VM  [deprecated]
                  The default VM is client.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument


C:\FirstHibernateExample>java c:\FirstHibernateExample.de.laliluna.example.Hello
World
Exception in thread "main" java.lang.NoClassDefFoundError: c:\FirstHibernateExam
ple/de/laliluna/example/HelloWorld

C:\FirstHibernateExample>
0
 

Author Comment

by:BrijBhasin
ID: 16558397
C:\FirstHibernateExample>java -cp c:\FirstHibernateExample java de.laliluna.exam
ple.HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: java

0
 
LVL 92

Expert Comment

by:objects
ID: 16558403
sorry typo, should have been

java -cp c:\FirstHibernateExample de.laliluna.example.HelloWorld
0
 

Author Comment

by:BrijBhasin
ID: 16558419
C:\FirstHibernateExample>java -cp c:\FirstHibernateExample de.laliluna.example.H
elloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: de/laliluna/example/H
elloWorld
0
 
LVL 92

Expert Comment

by:objects
ID: 16558439
and the follwoing file definitly exist?

c:\FirstHibernateExample\de\laliluna\example\HelloWorld.class

0
 

Author Comment

by:BrijBhasin
ID: 16558445
it exists here C:\FirstHibernateExample\bin\de\laliluna\example
0
 
LVL 92

Expert Comment

by:objects
ID: 16558461
then try:

java -cp c:\FirstHibernateExample\bin de.laliluna.example.HelloWorld
0
 

Author Comment

by:BrijBhasin
ID: 16558471

C:\FirstHibernateExample>java -cp c:\FirstHibernateExample\bin de.laliluna.examp
le.HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: de/laliluna/example/H
elloWorld (wrong name: HelloWorld)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)

0
 
LVL 92

Expert Comment

by:objects
ID: 16558484
actually its TestExample you're trying to run isn't it :)

java -cp c:\FirstHibernateExample\bin de.laliluna.example.TestExample
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16558699
First Check if TestExample.class exists(not TestExample.java file)

I doudt  it

else

First Use javac to compile the program which will create the TestExample.class file.

Then go to c:\FirstHibernateExample\bin  in commandline and use

java de.laliluna.example.TestExample

It must work if the class file is there.

Are you talking about the same tutorial

http://www.laliluna.de/first-hibernate-example-tutorial.html

use eclipse all these classpath problems won't trouble you much.

Thank You.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16562084
0
 

Author Comment

by:BrijBhasin
ID: 16563043
I'm using Eclipse and that is how I built the application. TestExample.class does exist in the directory. How can I run TestExample.class from eclipse
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 800 total points
ID: 16563340
Add its directory/ folder into the build-path by right-clicking on the project -> Properties -> Java Build Path
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16563348
If it is in a package like de.laliluna.example.TestExample, add the parent directory of de to the build-path.
0
 
LVL 23

Assisted Solution

by:Siva Prasanna Kumar
Siva Prasanna Kumar earned 400 total points
ID: 16563892
Just do a right click on TestExample.java file and select --> run as --> Java Application.

Thank You.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16564410
>> How can I run TestExample.class from eclipse

Oh you wanna run that class itself? Just add the source-file into a project and then run it.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 800 total points
ID: 16566286
> I'm using Eclipse and that is how I built the application. TestExample.class does exist in the directory.

You cannot run without the class file. You need to first compile the class.
If you built it in eclipse its probably somewhere else. In Eclipse check where the output folder is gfor the source folder that contains TestExample.java
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question