• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in running code in fedora 16

 
kiran gk
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

thanks in advance
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello kiran gk,

Welcome to CodeRanch!

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

This is because, your .class file lies in current directory (.), but current directory (.) is not part of your CLASSPATH. Add either '.' or path of src dir to the CLASSPATH.

Also, you should not point your JAVA_HOME to java executable. It should be pointing to /usr/java/jdk1.7.0_04/bin

I hope this helps.
 
kiran gk
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for replying

I did what you said but still its giving same error message
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.

Try doing below things:
1) Make sure that your classpath starts with '.' (i.e. CLASSPATH=.:<other jars>)
2) Make sure that classpath contains actual jars (instead of lib/*)
3) After doing this, if still there is problem then reply with output of echo %CLASSPATH
 
kiran gk
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WOW !!! It worked Thank you very much for your time and help
really feeling very happy

the problem is i missed : and .
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic