aspose file tools*
The moose likes Beginning Java and the fly likes Can't execute .class file created in NetBeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can Watch "Can New topic
Author

Can't execute .class file created in NetBeans

Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Hi,

I created this Swing java program in NetBeans and successfully compiled and run it (in NetBeans). However when I try to execute the program from the command prompt I keep getting some errors:

I typed:
java -classpath "c:\Program Files\Java\Java Files" Password_Generator

Exception in thread "main" java.lang.NoClassDefFoundError: org\jdesktop\layout\GroupLayout$Group

Anybody has an idea why this is so?
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
if you take a look at the source code for your Swing app,

netbeans tends to put package imports in the files which you

created with netbeans...

if this is the case, just comment/delete those out, and try
to compile and run it then, should work


Justin


You down with OOP? Yeah you know me!
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
But aren't those the codes that make up the actual GUI? If I remove them wouldn't it mess the GUI up? I mean there's a reason they are there right?
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
GroupLayout is the class used by Netbeans to create GUIs using Matisse. GroupLayout is standard in the JDK as of Java 1.6 (6). However prior to that you will need to make sure swing-layout-1.0.jar is on your classpath.
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Er... So does that mean I should really delete those code or is there something I need to do with the way I execute the program?
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
Well I'm going to assume you actually used GroupLayout to make your GUI, so its absolutely required (you most likely did if you used Netbeans visual GUI makes).

The good news all you have to do is add swing-layout-1.0.jar to your classpath. your current -classpath option adds the classes in the "c:\Program Files\Java\Java Files" directory to your classpath you just need to expand this to include swing-layout-1.0.jar like -classpath "c:\Program Files\Java\Java Files";c:\PATHTOJAR\swing-layout-1.0.jar

swing-layout-1.0.jar is somewhere in the netbeans directory.

Are you going to want to eventually distribute this? Then you should look at packaging your code in a jar with a MANIFEST.MF file and include your dependencies with it. Or use java web start. Or some third party installer. Or...
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
i dont know if you want to do it, but i had an assignment that
was originally created in netbeans, there was meaningless package imports..

remove the package imports that have to do with the file/classes you created...

and just make sure all the files are in the same directory, they should
compile and run fine...

i dont know about all that other stuff, but it always works for me...
i like visual studio better, netbeans/eclipse arent that great

[removed encouragement to use pirated software - Ilja]

lol Justin
[ October 22, 2006: Message edited by: Ilja Preuss ]
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
lol dont remove

import java.awt.*;
import java.awt.event.*;
import java.swing.*;

only the package declaration...

Justin
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Pretty cool. Now I have an executable jar file that can run the program outside NetBeans. It's a little annoying though to always have this swing-layout-1.0.jar in the same directory as my jar file. Is this really how it should be or is there a way for the program to run on its own?
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Make your GUI without NetBeans...


Regards, Rene Larsen
Dropbox Invite
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't execute .class file created in NetBeans