Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Not Able to Run Java Program From Eclipse

  1. #1
    Join Date
    Jan 2010
    Beans
    9

    Angry Not Able to Run Java Program From Eclipse

    Hi All,
    I am new to Ubuntu 9.10(even new to linux). I was previously using Windows OS. i am currently facing problem to run program using eclipse. In Eclipse, you can open a Java Class which contains main method, right click and chose to "Run as --> Java Application".

    On Windows , it works fine. But when i am doing same in Ubuntu, Eclipse throws ClassNotFound Exception...

    Here is Trace
    ---

    Exception in thread "main" java.lang.NoClassDefFoundError: com/Main
    Caused by: java.lang.ClassNotFoundException: com.Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
    Could not find the main class: com.Main. Program will exit.



    com.Main class contains main method..
    About Eclipse i am using ---
    Version: 3.5.1
    Build id: M20090917-0800


    Please help

  2. #2
    Join Date
    Jan 2007
    Location
    Michigan, USA
    Beans
    1,184
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Not Able to Run Java Program From Eclipse

    Java, Being not quite exactly cross platform from day one!

    It appears the the JVM for windows has one more bugfix than the one for Linux. That or you accidentally messed it up.

    I would bet more on the fact that closed source things for Linux (flash, java, nvidia) tend to be last on the dev lists for fixes.

    EDIT:
    I just thought of something else.

    Try adding a definition for main at the top of the file. possibly it is not optional under Linux.

    Or

    http://www.jguru.com/faq/view.jsp?EID=455768
    Last edited by t4thfavor; January 26th, 2010 at 07:20 AM.

  3. #3
    Join Date
    Jan 2010
    Beans
    9

    Re: Not Able to Run Java Program From Eclipse

    Quote Originally Posted by t4thfavor View Post
    Java, Being not quite exactly cross platform from day one!

    It appears the the JVM for windows has one more bugfix than the one for Linux. That or you accidentally messed it up.

    I would bet more on the fact that closed source things for Linux (flash, java, nvidia) tend to be last on the dev lists for fixes.

    EDIT:
    I just thought of something else.

    Try adding a definition for main at the top of the file. possibly it is not optional under Linux.

    Or

    http://www.jguru.com/faq/view.jsp?EID=455768
    I didn't get you here.... Could you pls explain

  4. #4
    Join Date
    Apr 2009
    Location
    Michigan
    Beans
    246
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Not Able to Run Java Program From Eclipse

    First, make sure you have both the JRE and JDK installed:
    Code:
    apt-get install sun-java6-jdk sun-java6-jre
    Or, if you'd prefer OpenJDK:
    Code:
    sudo apt-get install openjdk-6-jdk openjdk-6-jre
    (Not 100% sure about those install commands, so you could just grab those from the Software Center if the commands don't work.)

    Also, I had some issues when using the Eclipse from the Software Center. If you got Eclipse from the Ubuntu Software Center or Add/Remove... you could try removing it and installing Eclipse from the terminal with:

    Code:
    sudo apt-get install eclipse
    Hope this helps.
    My Laptop: Gateway T-6330u, 2.0 GHz Pentium Dual-Core, 3 GB RAM, 250 GB HDD - Windows Vista, Windows 7, Ubuntu 10.04.
    My Desktop: Dell Dimension 4600, 2.8 GHz Pentium 4, 1 GB RAM, 128 MB GeForce FX 5200, 120 GB HDD - Windows XP, Ubuntu 10.04.

  5. #5
    Join Date
    Jan 2010
    Beans
    9

    Re: Not Able to Run Java Program From Eclipse

    Quote Originally Posted by chessnerd View Post
    First, make sure you have both the JRE and JDK installed:
    Code:
    apt-get install sun-java6-jdk sun-java6-jre
    Or, if you'd prefer OpenJDK:
    Code:
    sudo apt-get install openjdk-6-jdk openjdk-6-jre
    (Not 100% sure about those install commands, so you could just grab those from the Software Center if the commands don't work.)

    Also, I had some issues when using the Eclipse from the Software Center. If you got Eclipse from the Ubuntu Software Center or Add/Remove... you could try removing it and installing Eclipse from the terminal with:

    Code:
    sudo apt-get install eclipse
    Hope this helps.
    I hava sun-java6-jdk install. It is working fine.

    I install Eclipse using "Synaptic Package Manger".
    did your mean, this could have problem itself ?

  6. #6
    Join Date
    Jan 2007
    Location
    Michigan, USA
    Beans
    1,184
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Not Able to Run Java Program From Eclipse

    Just throwing out possible answers for you as you had it working under Windows, and with Java being a C syntax language, I thought that maybe you had to add a definition to the top of the source file.

    like

    function main(int, int);

    Im not sure of the java syntax exactly, but the other post seems more likely the cause. Also check out that link as they say you need to setup the class path correctly.

    At least it's a start in the correct direction.

  7. #7
    Join Date
    Jan 2010
    Beans
    9

    Re: Not Able to Run Java Program From Eclipse

    Quote Originally Posted by t4thfavor View Post
    Just throwing out possible answers for you as you had it working under Windows, and with Java being a C syntax language, I thought that maybe you had to add a definition to the top of the source file.

    like

    function main(int, int);

    Im not sure of the java syntax exactly, but the other post seems more likely the cause. Also check out that link as they say you need to setup the class path correctly.

    At least it's a start in the correct direction.
    Thanks for your help & time..
    I am sure about the syntax is correct...

  8. #8
    Join Date
    Jan 2007
    Location
    Michigan, USA
    Beans
    1,184
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Not Able to Run Java Program From Eclipse

    Quote Originally Posted by parmendratyagi View Post
    Thanks for your help & time..
    I am sure about the syntax is correct...
    I meant my function definition syntax, I don't do java.

  9. #9
    Join Date
    Aug 2006
    Location
    Boulder
    Beans
    64
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Not Able to Run Java Program From Eclipse

    it would be easier to help you if you could send a screenshot of your eclipse workspace with your class that you want to run open.
    From looking at the error message I would assume you messed something up with the package name. Is your class in the right folder?

  10. #10
    Join Date
    Sep 2009
    Location
    Pennsylvania, USA
    Beans
    528
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Not Able to Run Java Program From Eclipse

    I had issues with Eclipse and Java previously. Here's what I did to fix it: I didn't install Eclipse from the repos. I just downloaded the .tar.gz file from the Eclipse website, extracted to a folder in my /home folder, and it works like a charm.

    If you've got issues when using Eclipse and Java, its quite possible that the issue is in the version of Eclipse (hence why I downloaded the files and untar'd them)

    http://www.eclipse.org/

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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