Results 1 to 3 of 3
  1. #1
    kirangk is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Hibernate library files problem

    Hi i am new to java and i have little knowledge of frameworks
    I used Hibernate in my project and its works fine in windows but in linux if i compile its giving error: Could not find or load main class

    check the below commands where i got stuck

    --- created java_home and path -------
    [root@saraswati ~]# echo $JAVA_HOME
    /usr/java/jdk1.7.0_04/bin/java
    [root@saraswati ~]# echo $PATH
    /usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.7.0_04/bin
    [root@saraswati ~]# cd /home/syslab/Downloads/src







    [root@saraswati src]# ls
    ------- these are the .java files-------
    Converter.java DataStorageHandler.java Hibernate.cfg.xml SensorReadings.hbm.xml UDPServer.java
    ConvertReadings.java FetchCoeff.java SensorMapping.java SensorReadings.java
    [root@saraswati src]# javac *.java


    ---- i am setting classpath inorder to compile .java files. lib folder contains all required libraries------

    [root@saraswati src]# export CLASSPATH=/home/syslab/Downloads/lib/*
    [root@saraswati src]# javac *.java
    [root@saraswati src]# java UDPServer
    Error: Could not find or load main class UDPServer
    ------- ths is the error i got -------




    [root@saraswati src]# java *
    Error: Could not find or load main class Converter.class
    --------------------------------------



    -------if i unset the classpath the code will run but it fails because of missing library files -------
    [root@saraswati src]# unset CLASSPATH
    [root@saraswati src]# java UDPServer
    Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/HibernateException
    at UDPServer.main(UDPServer.java:22)
    Caused by: java.lang.ClassNotFoundException: org.hibernate.HibernateException
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    ... 1 more
    ------------- this is the error ------------------------------


    can anyone solve this problem i am totally stuck in this

    thanx in advance

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Hibernate library files problem

    The preferred way of setting the classpath is to use the -cp switch for both javac and java.
    In your case, the CLASSPATH only contains the lib directory where your jars are, so when java tries to run, it runs using that lin directory, which doesn't have that class in it.

    Anyway, as I say, use -cp and don't forget to include '.':
    java -cp.;<any other directories> <your main class>

    The same applies to javac as well.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    kirangk is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: Hibernate library files problem

    It worked Thank you very much for your time and help :) :)
    really feeling very happy :)

Similar Threads

  1. Replies: 2
    Last Post: 06-11-2011, 02:54 PM
  2. external library problem
    By jperson in forum Eclipse
    Replies: 2
    Last Post: 05-17-2011, 10:25 AM
  3. Problem with .jar iReport (library ?)
    By mine0926 in forum NetBeans
    Replies: 6
    Last Post: 11-27-2010, 01:55 AM
  4. problem in loading library
    By rams in forum New To Java
    Replies: 0
    Last Post: 11-04-2008, 09:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •