File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes problem in running code in fedora 16 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "problem in running code in fedora 16" Watch "problem in running code in fedora 16" New topic
Author

problem in running code in fedora 16

kiran gk
Greenhorn

Joined: May 09, 2012
Posts: 5
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

Joined: Dec 08, 2010
Posts: 1506
    
    5

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.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
kiran gk
Greenhorn

Joined: May 09, 2012
Posts: 5
thanks for replying

I did what you said but still its giving same error message
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

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

Joined: May 09, 2012
Posts: 5
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

Joined: Dec 08, 2010
Posts: 1506
    
    5

You are welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in running code in fedora 16