Eclipse not working correctly on Mac with simple Java Program

Discussion in 'Mac Programming' started by Mork, Jan 25, 2009.

  1. Mork macrumors 6502

    Jan 9, 2009
    I have an Eclipse project that seems to be OK on the Mac, but when I created a brand new project and a class called "" with the code below, I get a....

    "Exception in thread "main" java.lang.NoClassDefFoundError: EnumTest" error.

    The same code runs fine on Eclipse under Windows.

    Anyone suggest what might be wrong?

    Thanks in advance.



    // Class is saved as: ""

    public class EnumTest
    public static void main(String[] args)
    // TODO Auto-generated method stub


    I've looked at the Eclipse build path and it has the "JVM 1.5.0 Mac OS/X Default" loaded.

    Also tried a project clean, refresh, all the usual stuff.

    There must be a configuration issue going on here, but I don't see what it is. I've never had this problem under Windows.
  2. neonblue2 macrumors 6502a

    Aug 25, 2006
    Port Pirie, South Australia
    It's definitely something wrong with Eclipse. I know next to nothing about Java but javac compiles your code perfectly fine.

    Are there any options for what compiler is used or how it is used? Check there maybe.
  3. Mork thread starter macrumors 6502

    Jan 9, 2009
    Thanks for your reply.

    I'll keep investigating....

  4. eddietr macrumors 6502a

    Oct 29, 2006
    That's very strange. Just as a sanity check, I created a project on my Mac, pasted your code in, and works perfectly fine.

    So did you try copying the working project from your Windows computer to your Mac and trying that?

    Also what version of Eclipse are you running?

    And lastly, if you want to zip up the (non-working) project directory and post it, it should be tiny. And then maybe someone could take a look.
  5. Mork thread starter macrumors 6502

    Jan 9, 2009
    Yeah, it works fine on the PC version.

    I'm using MyEclipse version 7, the latest and greatest.

    There must be something strange going on since I have another project in MyEcipse that works fine.

    If I intentionally introduce a syntax error, this project (the one that won't run) will give me a red underline and a small x at the left margin. So, it's finding a Java compiler, right?

    Thanks for the suggestions.

  6. eddietr macrumors 6502a

    Oct 29, 2006
    So my guess would be that your source folder is not on the build path.

    I've never used MyEclipse, but on Eclipse proper you can find that under the Properties of the project under "Java Build Path". Might want to check that.
  7. Mork thread starter macrumors 6502

    Jan 9, 2009
    MyEclipse is just a plug-in for Eclipse so your suggestion was totally valid, thanks.

    Unfortunately, src and all subfolders were "included" on build path.

    I removed them and re-added them, but it still doesn't work.

    I'll follow up with the MyEclipse folks tomorrow.

    I so dislike (seemingly) brittle software like this!

  8. plinden macrumors 68040


    Apr 8, 2004
    That's not a compilation error. The problem is that on running it, the jvm can't find the compiled class.

    How exactly how are you running it? From the command line or from the Run dialog in Eclipse?

    If you're running within Eclipse, check the Run Configuration. Under the classpath tab, is the EnumTest class listed under "User Entries"?

    Do you have Build Automatically (from under the Project menu) checked?

    Is the EnumTest.class file present in the bin directory of your EnumTest workspace?

    It's likely just a configuration problem rather than an underlying Eclipse problem. Still, Eclipse has indeed been rather brittle with recent releases. I occasionally get into states where it's easier to just delete it and reinstall than to try to fix it. That's with OS X, Windows and Linux so it's not OS-specific.
  9. wrldwzrd89 macrumors G5


    Jun 6, 2003
    Solon, OH
    I suspect I know what the problem might be.

    If my hunch is correct, Java itself doesn't like the name of your class. This is because "enum" is a keyword in Java 5, which I assume is what you're using.
  10. plinden macrumors 68040


    Apr 8, 2004
    No, using EnumTest wouldn't be a problem. You can even use Enum as a class name since the built-in Enum class is just that, another class.
  11. Mork thread starter macrumors 6502

    Jan 9, 2009
    Great suggestions.

    Yes, running the code from run button.

    The project is listed in the Classpath, but not the individual .class file. I think that's OK, since another project that does run looks the same.

    In the "Main" tab, the project entry is correct and the main program is correct. For grins, I had it search for the main program again and it found it.

    However, I still get the error when trying to run the main class "Run As ... Java Application" (as always for these types of programs).

    What could be wrong?

    I don't get this.
  12. plinden macrumors 68040


    Apr 8, 2004
    Did the project build? Check your project's bin directory for the EnumTest.class.

    Edit:Hmm, ok, I tried to reproduce this with some reasonable assumptions - a new Project with Build Automatically off, JDK 1.5

    Run As ... java application still works. The .class file was built during the Run As ...

    Edit 2:Can you try with a standard Eclipse install? Is there anything MyEclipse provides that you need? (You can just download the eclipse package and unpack it in your home directory, and run it from there, so you don't overwrite your current install). If that works, then it's likely something the MyEclipse plugin is causing.

    I use just the standard Eclipse with p4 and maven 2 plugins.
  13. Mork thread starter macrumors 6502

    Jan 9, 2009
    OK, I figured it out. Jeeez!

    The problem (not sure why, however) was that this was an old workspace folder I copied over from my Windows XP machine. When I did a switch workspace and selected it before, I didn't pay any attention (seemed OK at the time <s>) when it said:


    The total path to the workspace in Eclipse was a strange combination of a Unix Path /.... and then C:\.....


    So, I'm not sure why I can't create a new project in the old workspace folder, but somehow, the Mac/Eclipse is getting confused.

    In any case, if I create a project in the MyEclipse "Workspaces" on the Mac where MyEclipse was installed, all works fine.

    Thanks very much to all for the kind and numerioius replies and things to try!


    P.S. If anyone knows how to auto-start Tomcat using launchd, I'd appreciate a tip on how to do this. There's a utility that supposedly helps create launchd scripts, but it doesn't run for me (double-click -> nothing).
  14. plinden macrumors 68040


    Apr 8, 2004
    Are you talking about Lingon? Can you see /var/log/system.log when running your utility to see if anything is logged?

    You don't need a utility anyway - you can do it from Terminal.

    It's mentioned here -

    And google books has O'Reilly's Tomcat: The Definitive Guide available -,M1

    It has a section on Tomcat and launchd.
  15. eddietr macrumors 6502a

    Oct 29, 2006
    I don't think entire workspace directories are meant to be portable from installation to installation, let alone across platforms.

    There is no problem moving individuals projects from workspace to workspace even across platforms.
  16. Mork thread starter macrumors 6502

    Jan 9, 2009
    Interesting. I'll do some more testing now that I know what caused the initial problem.


    - M

Share This Page