Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
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 "EnumTest.java" 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.

M

---------------------

// Class is saved as: "EnumTest.java"

public class EnumTest
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
System.out.println("hello");
}

}

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.
 

neonblue2

macrumors 6502a
Aug 25, 2006
523
0
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.
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
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.
 

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
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.

M
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
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.
 

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
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!

Thanks.
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
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.
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
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.
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
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.
 

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
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.
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
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.
 

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
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:

C:\.....Workspace\....

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!

M

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).
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
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).

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 - http://blog.lo-fi.net/2008/01/leopard-for-web-developer-running.html

And google books has O'Reilly's Tomcat: The Definitive Guide available - http://books.google.com/books?id=vJttHyVF0SUC&pg=PA1&source=gbs_toc_r&cad=0_0#PPP1,M1

It has a section on Tomcat and launchd.
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
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.

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.
 

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
Interesting. I'll do some more testing now that I know what caused the initial problem.

Thanks!

- M
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.